| Development Environment | ![]() |
Exporting Delimited ASCII Data Files
To export an array as a delimited ASCII data file, you can use either the save command, specifying the -ASCII qualifier, or the dlmwrite function. The save command 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 Command
A = [ 1 2 3 4 ; 5 6 7 8 ];
use the save command, as follows.
save my_data.out A -ASCII
If you view the created file in a text editor, it looks like this.
1.0000000e+000 2.0000000e+000 3.0000000e+000 4.0000000e+000 5.0000000e+000 6.0000000e+000 7.0000000e+000 8.0000000e+000
By default, save uses spaces as delimiters but you can use tabs instead of spaces by specifying the -tabs qualifier.
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
104 101 108 108 111
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,
A = [ 1 2 3 4 ; 5 6 7 8 ];
as an ASCII data file that uses semicolons as a delimiter, use this command
dlmwrite('my_data.out',A, ';')
If you view the created file in a text editor, it looks like this
1;2;3;4 5;6;7;8
Note that dlmwrite does not insert delimiters at the end of rows.
By default, if you do not specify a delimiter, dlmwrite uses commas as a delimiter. You can specify a space (' ') as a delimiter or, if you specify empty quotes (''), no delimiter.
| Exporting ASCII Data | Using the diary Command to Export Data | ![]() |