Development Environment | ![]() ![]() |
Exporting ASCII Data
MATLAB supports several ways to export data in many different ASCII formats. For example, you may want to export a MATLAB matrix as text file where the rows and columns are represented as space-separated, numeric values.
This section describes how to use MATLAB functions to export data in several common ASCII formats, including:
The function you use depends on the amount of data you want to export and its format.
If you are not sure which section describes your data, scan the data format samples in Table 6-3 and look for the sample that most nearly matches the data format you want to create. Then, read the section referred to in the table.
If you are familiar with MATLAB export function but not sure when to use them, view Table 6-4, which compares the features of each function.
Data Format Sample |
MATLAB Export Function |
1 2 3 4 5 |
See Exporting Delimited ASCII Data Files and Using the diary Command to Export Data for information about these options. |
1; 2; 3; 4; 5; |
See Exporting Delimited ASCII Data Files for more information. The example shows a semicolon-delimited file but you can specify other characters as the delimiter. |
Function |
Use With |
Delimiters |
Notes |
diary |
Numeric data or cell array |
Only spaces |
Can be used for small arrays. Requires editing of data file to remove extraneous text. |
dlmwrite |
Numeric data |
Any character |
Easy to use, flexible. |
fprintf |
Alphabetic and numeric data |
Any character |
Part of low-level file I/O routines. Most flexible command but most difficult to use. Requires use of fopen to obtain file identifier and fclose after write. |
save |
Numeric data |
Tabs or spaces |
Easy to use; output values are high precision. |
![]() | Importing Mixed Alphabetic and Numeric Data | Exporting Delimited ASCII Data Files | ![]() |