Quantcast

Documentation Center

  • Trial Software
  • Product Updates

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

Description

For More Information, 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

readtable

Import column-oriented data into a table.

Import Mixed Text and Numeric Data from Text Files

csvread

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

Import Comma-Separated Data

dlmread

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

Import Delimited Numeric Data

textscan

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?