Main Content

Methods for Importing Data


When you import data into the MATLAB® workspace, the new variables you create overwrite any existing variables in the workspace that have the same name.

Tools that Import Multiple File Formats

You can import data into MATLAB from a disk file or the system clipboard interactively.

To import data from a file, do one of the following:

  • On the Home tab, in the Variable section, select Import Data .

  • Double-click a file name in the Current Folder browser.

  • Call uiimport.

To import data from the clipboard, do one of the following:

  • On the Workspace browser title bar, click , and then select Paste.

  • Call uiimport.

To import without invoking a graphical user interface, the easiest option is to use the importdata function.

For a complete list of the formats you can import interactively or with importdata, see Supported File Formats for Import and Export.

Importing Specific File Formats

MATLAB includes functions tailored to import specific file formats. Consider using format-specific functions instead of importing data interactively when you want to import only a portion of a file. Many of the format-specific functions provide options for selecting ranges or portions of data. Some format-specific functions allow you to request multiple optional outputs. This option is not available when you import interactively.

For a complete list of the format-specific functions, see Supported File Formats for Import and Export.

For binary data files, consider Overview of Memory-Mapping. Memory-mapping enables you to access file data using standard MATLAB indexing operations.

Alternatively, MATLAB toolboxes perform specialized import operations. For example, use Database Toolbox™ software for importing data from relational databases. Refer to the documentation on specific toolboxes to see the available import features.

Importing Data with Low-Level I/O

If the Import Wizard, importdata, and format-specific functions cannot read your data, use low-level I/O functions such as fscanf or fread. Low-level functions allow the most control over reading from a file, but require detailed knowledge of the structure of your data. For more information, see: