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.
For More Information, See...
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 column-oriented data into a table.
Import a file or range of comma-separated numeric data to a matrix.
Import a file or a range of numeric data separated by any single delimiter to a matrix.
Import a nonrectangular or arbitrarily formatted text file to a cell array.
For information on importing files with more complex formats, see Import Text Data Files with Low-Level I/O.