Development Environment    

Exporting ASCII Data

This section describes how to use MATLAB functions to export data in several common ASCII formats. For example, you can use these functions to export a MATLAB matrix as a text file where the rows and columns are represented as space-separated, numeric values. The function you use depends on the amount of data you want to export and its format. Topics covered include
Exporting Delimited ASCII Data Files
Describes how to use the save command or the dlmwrite function
Using the diary Command to Export Data
Describes how to use the diary command to export data

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 functions but are not sure when to use them, view Table 6-4, which compares the features of each function.

Table 6-3: ASCII Data File Formats and MATLAB Export Commands

Data Format Sample
MATLAB Export Function
1 2 3 4 5
6 7 8 9 10

See Exporting Delimited ASCII Data Files and Using the diary Command to Export Data for information about these options.
1; 2; 3; 4; 5;
6; 7; 8; 9; 10;

See Exporting Delimited ASCII Data Files for more information. The example shows a semicolon-delimited file, but you can specify another character as the delimiter.
Table 6-4: ASCII Data Export Function Feature Comparison

Function
Use With
Delimiter
Notes
csvwrite
Numeric data
Only comma
Primarily used with spreadsheet data. See also the binary format spreadsheet export functions.
diary
Numeric data or cell array
Only space
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. This is the most flexible command but also the most difficult to use. You must use fopen to obtain a file identifier before writing the data and fclose to close the file after writing the data.
save
Numeric data
Tab or space
Easy to use; output values are high precision.

  Importing Mixed Alphabetic and Numeric Data Exporting Delimited ASCII Data Files