This is machine translation

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

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Text Files

Delimited and formatted text files

Read and write numeric and nonnumeric data in delimited and formatted text files, including .csv and .txt files. Import text file data interactively using the Import Tool. Import or export text data programmatically using the functions on this page. To compare primary import options for text files, see Ways to Import Text Files.


readtableCreate table from file
detectImportOptionsCreate import options based on file content
writetableWrite table to file
textscanRead formatted data from text file or string
dlmreadRead ASCII-delimited file of numeric data into matrix
dlmwriteWrite matrix to ASCII-delimited file
csvreadRead comma-separated value (CSV) file
csvwriteWrite comma-separated value file
typeDisplay contents of file

Using Objects

DelimitedTextImportOptionsImport options object for delimited text
FixedWidthImportOptionsImport options object for fixed-width text files

Examples and How To

Select Text File Data Using Import Tool

This example shows how to import data from a text file with column headers and numeric data using the Import Tool.

Import Numeric Data from Text Files

This example shows how to import comma-separated numeric data from a text file, using the csvread function.

Import Mixed Data from Text Files

This example shows how to use the readtable function to import mixed data from a text file into a table.

Import Large Text File Data in Blocks

This example shows how to read small blocks of data from an arbitrarily large delimited text file using the textscan function and avoid memory errors.

Import Data from a Nonrectangular Text File

This example shows how to import data from a nonrectangular file using the textscan function.

Import Dates and Times from Text Files

Formatted dates and times (such as '01/01/01' or '12:30:45') are not numeric fields.

Write to Delimited Data Files

To export a numeric array as a delimited ASCII data file, you can use either the save function, specifying the -ASCII qualifier, or the dlmwrite function.

Import or Export a Sequence of Files

To import or export multiple files, create a control loop to process one file at a time.

Define Import Options for Tables

For customized data import and additional control over the import process, define and use the import options.


Ways to Import Text Files

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

Was this topic helpful?