Reputation: 11
I am trying to save an output of matlab in ascii. It works but the problem is that the format is:
4.8143374e+07 1.0000000e+00 1.0000000e+00
1.0000000e+00 2.0000000e+00 4.0000000e+00
but I need 6 digits precision and round brackets like
(4.8143374e+07 1.0000000e+00 1.0000000e+00)
(1.0000000e+00 2.0000000e+00 4.0000000e+00)
Do you know how how I can do that? Thank you
best regards L.Metelli
Upvotes: 1
Views: 108
Reputation: 2621
Using the sprintf
function you can print data into formatted strings:
http://www.mathworks.de/de/help/matlab/ref/sprintf.html
Out of my head something like
str = sprintf("(%f.6 %f.6 %f.6)", data(0), data(1), data(2))
might work.
Upvotes: 0
Reputation: 319
You probably want to use fprintf()
to write to a file and give it the following format specifier:
% After opening your file like this: fid = fopen('myfile.asc', 'wt');
fprintf(fid, '(%0.6e %0.6e %0.6e)\n', data(1), data(2), data(3));
If you leave out the fid
in the call to fprintf()
, the results will be displayed in the command window.
Upvotes: 3