Selectively setting significant digits in display
10 views (last 30 days)
Show older comments
Hi, My program outputs a 2-column array of numbers. I wish to display the first column numbers with the precision of 2 decimal places. However, I want the second column to be displayed with a 9 decimal precision. May someone please suggest the way to do this?
Thanks.
0 Comments
Accepted Answer
Jiro Doke
on 5 Feb 2011
Here's a short example:
% Create 2-column array of random numbers (0 - 1)
num = rand(10, 2);
% Make some values greater than 10 or 100
num(10) = num(10)+10;
num(15) = num(15)+100;
% Display with specified number of digits
% Note: transpose "num".
fprintf('%6.2f %13.9f\n', num');
This displays:
0.91 0.494173937
0.80 0.779051723
0.10 0.715037078
0.26 0.903720561
0.34 100.890922504
0.68 0.334163053
0.14 0.698745832
0.72 0.197809827
0.11 0.030540946
10.65 0.744074260
More Answers (0)
See Also
Categories
Find more on Logical 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!