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.

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 ways to import for text files, see Ways to Import Text Files.

Functions

expand all

Import ToolImport data from file

Basic Import and Export

readtableCreate table from file
writetableWrite table to file

Define Import Rules

detectImportOptionsCreate import options based on file content
delimitedTextImportOptionsImport options object for delimited text
fixedWidthImportOptionsImport options object for fixed-width text files
getvaroptsGet variable import options
setvaroptsSet variable import options
setvartypeSet variable data types
previewPreview eight rows from file using import options
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
filereadRead contents of file as text

Objects

tabularTextDatastoreDatastore for tabular text files

Topics

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 Dates and Times from Text Files

Import formatted dates and times (such as '01/01/01' or '12:30:45') from column oriented tabular data in three ways.

Read Collection or Sequence of Text Files

Read and manage data from a collection of text files.

Define Import Options for Tables

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

Write Data to Text Files

Export tabular data contained in tables, cell arrays, or numeric arrays from the MATLAB workspace to text files.