Programming Previous page   Next Page

Exporting Delimited ASCII Data Files

To export an array as a delimited ASCII data file, you can use either the save function, specifying the -ASCII qualifier, or the dlmwrite function. The save function is easy to use; however, the dlmwrite function provides more flexibility, allowing you to specify any character as a delimiter and to export subsets of an array by specifying a range of values.

Using the save Function

To export the array A,

use the save function, as follows:

If you view the created file in a text editor, it looks like this:

By default, save uses spaces as delimiters but you can use tabs instead of spaces by specifying the -tabs option.

When you use save to write a character array to an ASCII file, it writes the ASCII equivalent of the characters to the file. If you write the character string 'hello' to a file, save writes the values

Using the dlmwrite Function

To export an array in ASCII format and specify the delimiter used in the file, use the dlmwrite function.

For example, to export the array A,

as an ASCII data file that uses semicolons as a delimiter, use this command:

If you view the created file in a text editor, it looks like this:

Note that dlmwrite does not insert delimiters at the end of rows.

By default, if you do not specify a delimiter, dlmwrite uses a comma as a delimiter. You can specify a space (' ') as a delimiter or, if you specify empty quotes (''), no delimiter.


Previous page  Exporting Text Data Using the diary Function to Export Data Next page

© 1994-2005 The MathWorks, Inc.