1

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

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

1 Comment

I think you need .6

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.