Documentation

Import Tool

Import data from file

Description

TheImport Tool让你预览和导入电子表格中的数据files, delimited text files, and fixed-width text files. You can interactively select the data to import and reuse the script or function that the tool generates to import other similar files.

Open the Import Tool App

  • MATLAB®Toolstrip: On theHometab, in theVariable部分中,点击Import Data.

  • MATLAB command prompt: Enteruiimport(filename), wherefilenameis a character vector specifying the name of a text or spreadsheet 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. PressCtrlto select noncontiguous ranges.

Modify theVariable Names Rowfield to indicate the row you want the Import Tool to use for the variable names.

By default,NaNreplaces unimportable values in numeric cells. However, you can change this value to any other numeric value. Specify how to treat unimportable values on theImporttab, in theUnimportable Cellssection.

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

ClickImport Selection. The new column vectors appear in your workspace.

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 theImported Datasection, selectTableto import the file data into atablevariable. In this example, the third column of data contains monetary amounts where the decimal separator is a comma. In theDelimiterssection, selectDelimiter Options. Then, underDecimal Separator, select, (comma).

The Import Tool appropriately converts the monetary values.

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

ClickImport Selectionto import the table.

Related Examples

Programmatic Use

expand all

uiimportopens 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 infilenameusing eitherImport ToolorImport Wizarddepending on the file type. For spreadsheet and text files,uiimportopens the file usingImport Tool. For all other file types, such as image, audio, or MAT-files,uiimportopens the file usingImport Wizard.

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

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

S = uiimport(___)opens the file usingImport Wizardand stores the resulting variables as fields in the structS.