fprintf %f
Show older comments
I have an fprintf command
fprintf('\n %s \n%0.3f',Data{:})
where my data contains a sentence and then an array. I want the decimal places for the array to only go to 3 which seems only work for every other number. So every thing comes out fine but it looks like this:
Sentence
1.784
2.862691e+000
2.737
2.855501e+000
2.976
i dont want the exponentials
1 Comment
Jan
on 1 Oct 2011
Please post the contents of the Data cell. I cannot imagine, that the posted format string can create the shown answer.
Accepted Answer
More Answers (1)
Jan
on 1 Oct 2011
I guess that your Data are:
Data = {'Sentence', [1.784, 2.862691, 2.737, 2.855501, 2.976]};
When you use the format string '\n %s \n%0.3f' every second number is displayed using the '%s' format. So you have to split the string from the numerical data:
fprintf('\n %s', Data{1});
fprintf(' \n%0.3f', Data{2});
Or perhaps: fprintf(' \n%0.3f', Data{2:end});
Categories
Find more on Image Arithmetic in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!