Define Import Options for Table in MATLAB
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.
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.
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.
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.
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.
Display the first eight rows of the table after specifying the variables to be obtained and importing them with read table.
Please Login to comment...