Tags: ascii, columns, export, file, firstcolumn, format, matlab, programming, save
Save data as ASCII
I have a problem to export the data as ASCII format.
I need to export the data as a file with three columns. The first
column is for the first variable, and the second column is for the
second variable, and so on. Something like this:
x y z
0.0 2 2.3
0.05 2.3 3.1
0.1 1.2 2.4
0.15 1.6 3.5
When I use the command save('xyz.dat', '-ASCII', 'x', 'y', 'z'), the
values are appended instead of the above format.
I appreciate all help from anybody.
Leave a comment...
- 1 Comments
- If you have your data in row vectors x, y and z you can easily build
the file text using sprintf:
fileText = sprintf('%g %g %g\n', [x, y, z]);
If you have column vectors, transpose x, y and z before.
The output may contain something like "3.14159e-010" which might not
be allowed in your application. In that case, use a different format
specifer than "%g".
Now just add the variable names
[sprintf('x y z\n'), fileText];
and write to a file:
fid = fopen('test.txt', 'w');
Markus#1; Mon, 12 May 2008 11:18:00 GMT