This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.

Ways to Import Text Files

You can import text files into MATLAB® both interactively and programmatically.

To import data interactively, use the Import Tool. You can generate code to repeat the operation on multiple similar files. The Import Tool supports text files, including those with the extensions .txt, .dat, .csv, .asc, .tab, and .dlm. These text files can be nonrectangular, and can have row and column headers, as shown in the following figure. Data in these files can be a combination of numeric and nonnumeric text, and can be delimited by one or more characters.

To import data from text files programmatically, use an import function. Most of the import functions for text files require that each row of data has the same number of columns, and they allow you to specify a range of data to import.

This table compares the primary import options for text files.

Import Option


For Examples, See...

Import Tool

Import a file or range of data to column vectors, a matrix, a cell array, or a table. You can generate code to repeat the operation on multiple similar files.

Select Text File Data Using Import Tool


Import column-oriented data into a table.

Import Mixed Data from Text Files

Define Import Options for Tables


Import a file or range of comma-separated numeric data to a matrix.

Import Comma-Separated Data


Import a file or a range of numeric data separated by any single delimiter to a matrix.

Import Delimited Numeric Data

TabularTextDatastore with read or readall functions

Import one or more column-oriented text files. Each file can be very large and does not need to fit in memory.

Read and Analyze Large Tabular Text File


Import a nonrectangular or arbitrarily formatted text file to a cell array.

Import Data from a Nonrectangular Text File

For information on importing files with more complex formats, see Import Text Data Files with Low-Level I/O.

Was this topic helpful?