Read and write numeric and non-numeric data in delimited and formatted text files,
.txt files. Import text file data
interactively using the Import Tool. Import or export text
data programmatically using the functions on this page.
|Create table from file|
|Write table to file|
|Create timetable from file|
|Write timetable to file|
|Create import options based on file content|
|Import options object for delimited text|
|Import options object for fixed-width text files|
|Import options object for XML Files|
|Get variable import options|
|Set variable import options|
|Set variable data types|
|Preview eight rows from file using import options|
|Read matrix from file|
|Write a matrix to a file|
|Read cell array from file|
|Write cell array to file|
|Read variables from file|
|Read formatted data from text file or string|
|Display contents of file|
|Read contents of file as text|
|Read lines of file as string array|
|Datastore for tabular text files|
Text files often contain a mix of numeric and text data as well as variable and row names, which is best represented in MATLAB® as a table.
Preview tabular data from a text file or the clipboard and select data to import using the Import tool.
The best way to represent tabular data from text files in MATLAB is in a table since tables can store heterogeneous (a mix of numeric and text) data, as well as variable and row names.
Import block formatted tabular data from a text file into a table or a cell array.
In addition to importing numeric tabular data from a text file as a table
readtable, you can also import this data as a matrix
into the MATLAB workspace.
Read arbitrary block-formatted numeric data from a text file into cell arrays.
This example shows how to create a datastore for a large text file containing tabular data, and then read and process the data one block at a time or one file at a time.
Import formatted dates and times (such as
'12:30:45') from column
oriented tabular data.
Read and manage data from a collection of text files.
If you want to control the import process beyond the options provided by the
readtable function, such as defining how to handle
missing data or errors, then create an import options object before importing
Export tabular data contained in tables, cell arrays, or numeric arrays from the MATLAB workspace to text files.