Documentation

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.

Functions

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

Using Objects

DelimitedTextImportOptions Import options object for delimited text

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

Typically, you can import tables using the readtable function.

Concepts

Ways to Import Text Files

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

Was this topic helpful?