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.
readtable |
Create table from file |
detectImportOptions |
Create import options based on file content |
writetable |
Write table to file |
textscan |
Read formatted data from text file or string |
dlmread |
Read ASCII-delimited file of numeric data into matrix |
dlmwrite |
Write matrix to ASCII-delimited file |
csvread |
Read comma-separated value (CSV) file |
csvwrite |
Write comma-separated value file |
type |
Display contents of file |
DelimitedTextImportOptions |
Import options object for delimited text |
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.
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
Typically, you can import tables using the readtable function.
You can import text files into MATLAB® both interactively and programmatically.