Define Import Options for Table in MATLAB
Last Updated :
28 Apr, 2025
The import tool lets you import into a table or another type of data. Take into consideration reading data from the sample spreadsheet file patients.xls into MATLAB as a table. Open the file with the Import Tool, select the output format and date range, and save. After you click the Import Selection button, the data will be imported into the MATLAB workspace. Tabular data can be imported into MATLAB Workspace and the SimBiology Model Analyzer app. Supported file extensions include Excel® files (.xls,.xlsx), SAS XPORT files (.xpt), and text files (.csv,.txt). You can also specify that the data come from a file formatted. During the import process, the NONMEM definitions are used to interpret the columns.
Import Tool in MATLAB:
Click Import Data in the Variable section of the Home tab. A different option is to right-click the file name in the Current Folder browser and select Import Data. Import Tool starts up.
Define Import Options for Table:
Importing tables requires using the read table function. However, there are occasions when importing tabular data calls for additional control over the import process. You might want to select the variables that will be used to import rows with data that is missing or causes errors. To control the import process, you can create an import options object. The object's properties can be changed to meet your import requirements.
Create an import options object for the Buildings.csv test data set using the detectImportOptions function. The DelimitedTextImportOptions object is produced by the detectImportOptions function for this text file. The complete list of properties for the import options object is available on the detectImportOptions reference page.
Example 1:
Matlab
opts = detectImportOptions('Bulidings.csv');
 Â
Customize Table-Level Import Options:
The import options object's properties can be changed to control the import process. Several of the properties are applicable to the entire table, while others are only applicable to particular variables. Examples of properties that affect the entire table include rules for handling data that is missing or causes errors. For instance, you can eliminate rows containing data that cause import errors by setting the ImportErrorRule to "omit row."For any missing values to be replaced, set the MissingRule to "fill."The worth of the FillValue property replaces the missing qualities. NaN, for example, can replace missing qualities.
Matlab
opts.'omitrow' is the ImportErrorRule.
opts.MissingRule = 'fill';
Customize Variable-Level Import Options:
To get and set options for particular variables, use the functions getvaropts, setvartype, and setvaropts. To see the options that are currently available for the variables FlightNum, Origin, Dest, and ArrDelay, for example, use the getvaropts function.
Matlab
getvaropts(opts,{'BuildingsNum','HallsName in Buldings',
'Towers near Buildings','skyscraper Buildings'});
Using the setvartype function, modify the data types for the variables:
- Change the variable FlightNum's data type to char since its values are flight identifiers rather than numbers.
- Change the data type of the variables Origin and Dest to categorical since they represent a limited set of text values that repeat.
Matlab
opts = setvartype(opts,{'BuildingsNum',
'HallsName in Buldings','Towers near
Buildings','skyscraper Buildings'},..
{'char','categorical','categorical','single'});
 Â
Using the setvaropts function, modify additional properties:
- Set the WhiteSpaceRule property of the BuildingsNum variable to trim leading to eliminate any leading white spaces from the text.
- Set the TreatAsMissing property for the skyscraper Buildings variable to the value specified in the FillValue property to replace fields that contain 0 or NA.
Matlab
opts = setvaropts(opts,'BuildingsNum',
'WhitespaceRule','trimleading');
opts = setvaropts(opts,'skyscraper
Buildings','TreatAsMissing',{'0','NA'});
Import Table
Display the first eight rows of the table after specifying the variables to be obtained and importing them with read table.
reading
Output:
    Â
Â
Similar Reads
User defined function in MATLAB Functions let you do a specific task. User defined functions are the functions created by the users according to their needs. This article explains how the user defined function in MATLAB is created. Syntax : function [a1,...,an] = func(x1,...,xm) func is the function name a1,...,an are outputs x1,.
2 min read
GUI Based Tables in MATLAB GUI tables in MATLAB are graphical user interface that allow users to display and manipulate tabular data.They are used to create interactive applications that require data to be displayed in a table format. GUI tables in MATLAB typically consist of columns and rows , with each column representing a
3 min read
Configure the Run Button for Functions in MATLAB Functions are parts of program files that process inputs and generate outputs. Set the Run button to execute any additional Editor setup or functions that need argument values to be entered. To configure the Editor's Run button, click Run and type one or more run commands. We'll examine a setup exam
2 min read
Add Functions to Scripts in MATLAB From MATLAB version 2016b, it is possible to add functions directly into a script or live script. In this article, we shall how to add functions to script files. Â The syntax is simple except one rule that the function body must be written after the codes in the script. statement 1 statement 2 . stat
2 min read
Timetables in MATLAB Timetables are a type of tables in MATLAB that store a timestamp corresponding to each row. Similar to tables, timetables can store column-oriented data under a variable name (column name), where every variable has same number of rows. All the functions of a table work with timetables as well along
2 min read
Plot Expression or Function in MATLAB In this article, we will discuss how to plot expressions or functions in MATLAB. We can make use fplot() function in MATLAB to generate the plot corresponding to an expression or function. There are different variants of fplot() function fplot(f)fplot(f,xinterval)fplot(___,LineSpec)fplot(___,Name,Va
3 min read