Main Content

Import Tool

Import data from file

Description

The Import Tool lets you preview and import data from spreadsheet files, delimited text files, and fixed-width text files. In MATLAB® Online™, you can also preview and import data from netCDF files. You can interactively select the data to import and reuse the script or function that the tool generates to import other similar files.

Import Tool

Open the Import Tool

  • MATLAB Toolstrip: On the Home tab, in the Variable section, click Import Data.

  • MATLAB command prompt: Enter uiimport(filename), where filename is a character vector specifying the name of a text or spreadsheet file (or, in MATLAB Online, a netCDF file).

Examples

expand all

Import ranges of data from a tab-delimited text file and replace nonnumeric values in the file.

Drag the cursor to select the cells to import. Press Ctrl to select noncontiguous ranges.

Preview of text data import in the Import Tool. Some data elements are selected, and the Output Type field is set to Column vectors.

Modify the Variable Names Row field to indicate the row you want the Import Tool to use for the variable names.

Preview of text data import in the Import Tool. The Variable Names Row field is set to 3. The variable names are the values in the third row of data: CH1, CH2, and CH3.

By default, NaN replaces unimportable values in numeric cells. However, you can change this value to any other numeric value. Specify how to treat unimportable values on the Import tab, in the Unimportable Cells section.

Preview of text data import in the Import Tool. Unimportable cells are highlighted in yellow and are replaced with the value -99.0.

Alternatively, exclude any row that contains an unimportable cell from being imported.

Import Tool setting for text data import. Rows with unimportable cells are highlighted in purple and are excluded from the import.

Click the Import Selection button . The new column vectors appear in your workspace.

Workspace containing column vectors CH1 and CH3

Import dates and numbers from a text file into a table. Specify the decimal separator for numeric values in the file and a custom format for dates.

In the Imported Data section, select Table to import the file data into a table variable. In this example, the third column of data contains monetary amounts where the decimal separator is a comma. In the Delimiters section, select Delimiter Options. Then, under Decimal Separator, select , (comma).

The Import Tool appropriately converts the monetary values.

Import Tool settings. The Output Type field is set to Table, and the Delimiter Options field is set to a comma decimal separator.

Specify that a column contains date or time data by changing the data type for the column to DATE/TIME. Click more date formats.... Scroll down the list to enter a custom date format.

List of Import Tool options for date and time formats. There is a text field to apply a custom date format to the selected data.

Click the Import Selection button to import the table.

Related Examples

Programmatic Use

expand all

uiimport opens a dialog to interactively load data from a file or the clipboard. MATLAB displays a preview of the data in the file.

uiimport(filename) opens the file specified in filename using either Import Tool or Import Wizard depending on the file type. For spreadsheet and text files (and, in MATLAB Online, netCDF files), uiimport opens the file using Import Tool. For all other file types, such as image, audio, or MAT-files, uiimport opens the file using Import Wizard.

uiimport('-file') presents the file selection dialog first.

uiimport('-pastespecial') presents the clipboard contents first.

S = uiimport(___) opens the file using Import Wizard and stores the resulting variables as fields in the struct S.

Version History

expand all

See Also

Functions

Live Editor Tasks