Reputation: 319
I have a vector of doubles and I want to see what are the exact numbers inside the vector I get in format long.
1.0e+03 *
-0.002202883146567
1.182072110137121
-0.002242966651629
-0.000584787748712
0.022251505213305
0.037460846794487
Can I make some adjusment so that I can directly see the number, rounded to let's say the 5th or 6th element after the decimal point, whenever I type the name of the variable?
Upvotes: 1
Views: 54
Reputation: 19689
fprintf('%.6f\n', 0.037460846794487)
It'll round 0.037460846794487
to 6 decimal places as shown:
>> fprintf('%.6f\n', 0.037460846794487)
0.037461
Or you can also use sprintf('%.6f\n', 0.037460846794487)
, particularly, if you want to save the rounded off output in a variable.
>> a=sprintf('%.6f\n', 0.037460846794487)
a =
0.037461
and for the matrix you mentioned, you can make the following adjustment:
%Your matrix
A = 1.0e+03 * [ -0.002202883146567 ;
1.182072110137121 ;
-0.002242966651629 ;
-0.000584787748712 ;
0.022251505213305 ;
0.037460846794487 ];
A = sprintf('%.6f\n', A) %Adjusted to 6 decimal digits
Upvotes: 1