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.


expand all

Import ToolImport data from file

Basic Import and Export

readtableCreate table from file
writetableWrite table to file
readtimetableCreate timetable from file
writetimetableWrite timetable 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
readmatrixRead matrix from file
writematrixWrite a matrix to a file
readcellRead cell array from file
writecellWrite cell array to file
readvarsRead variables from file
textscanRead formatted data from text file or string
typeDisplay contents of file
filereadRead contents of file as text


tabularTextDatastoreDatastore for tabular text files


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.