Programming |
|
Exporting Text 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
If you are not sure which section describes your data, find the sample in the table below 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, see Table 6-4, which compares the features of each function.
Note
If C or Fortran routines for writing data files in the form needed by other applications exist, create a MEX-file to write the data. See the MATLAB External Interfaces documentation for more information.
Table 6-4: ASCII Data Export Function Features
Function
|
Use With
|
Delimiters
|
Notes
|
csvwrite
|
Numeric data
|
Commas only
|
Primarily used with spreadsheet data. See Working with Spreadsheets.
|
diary
|
Numeric data or cell array
|
Spaces only
|
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 function is the most flexible 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
|
Tabs or spaces
|
Easy to use; output values are high precision.
|
|
| Importing from XML Documents | | Exporting Delimited ASCII Data Files | |
© 1994-2005 The MathWorks, Inc.