File Exchange Pick of the Week

Our best user submissions

Import Explorer to help you with importing table data

When importing data as a table, you can use detectImportOptions to customize how you bring in your data. You can choose to import specific columns, specify the data type of each column, specify how to treat missing values, and many more.

Import Explorer

Jan's entry is a visual tool to help with this customization. It also lets you save the output for detectImportOptions so that you can programmatically reproduce the operation. See this in action.
import_explorer.gif

Programmatic Approach

As a comparision, here's how you would do it programmatically from scratch.
opts = detectImportOptions("airlinesmall.csv")
opts =
DelimitedTextImportOptions with properties: Format Properties: Delimiter: {','} Whitespace: '\b\t ' LineEnding: {'\n' '\r' '\r\n'} CommentStyle: {} ConsecutiveDelimitersRule: 'split' LeadingDelimitersRule: 'keep' TrailingDelimitersRule: 'ignore' EmptyLineRule: 'skip' Encoding: 'Shift_JIS' Replacement Properties: MissingRule: 'fill' ImportErrorRule: 'fill' ExtraColumnsRule: 'addvars' Variable Import Properties: Set types by name using setvartype VariableNames: {'Year', 'Month', 'DayofMonth' ... and 26 more} VariableTypes: {'double', 'double', 'double' ... and 26 more} SelectedVariableNames: {'Year', 'Month', 'DayofMonth' ... and 26 more} VariableOptions: Show all 29 VariableOptions Access VariableOptions sub-properties using setvaropts/getvaropts VariableNamingRule: 'modify' Location Properties: DataLines: [2 Inf] VariableNamesLine: 1 RowNamesColumn: 0 VariableUnitsLine: 0 VariableDescriptionsLine: 0 To display a preview of the table, use preview
opts.VariableTypes([9 17 18]) = {'categorical'};
opts.SelectedVariableNames = opts.VariableNames([1 2 3 5 7 9 10 15 16 17 18]);
data = readtable("airlinesmall.csv",opts);

Import Tool

Of course, there is the Import Tool that comes with MATLAB. You can do many of these customizations from the tool.
import_tool.png
Jan's Import Explorer gives you a bit more options, since detectImportOptions provides those. In addition, Jan's tool works with multiple files, in which case it uses the datastore function under the hood.
A small request I have is for this to work with other file types, such as Excel files. Currently, this tool only works with CSV and TXT files.

Comments

Give this a try and let us know what you think here or leave a comment for Jan.
|
  • print

Comments

To leave a comment, please click here to sign in to your MathWorks Account or create a new one.