This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Ways to Import Text Files

Choose an import method based on the format of your data and the desired data type in the MATLAB® workspace. Import text files interactively or 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.

Import text files in one of these ways.

Import Method


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.

Import Text File Data Using Import Tool


Import column-oriented data into a table.

Import Mixed Data from Text File

readtable with detectImportOptions function

Import data with additional control. For example, select the variables to import or handle rows with missing or error-causing data.

Define Import Options for Tables

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 Block of Numeric Data from Text File


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

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

See Also

| | | | |