Selectively setting significant digits in display

10 visualizaciones (últimos 30 días)
ANUBHAV SINHA
ANUBHAV SINHA el 5 de Feb. de 2011
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.

Respuesta aceptada

Jiro Doke
Jiro Doke el 5 de Feb. de 2011
Make use of fprintf.
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

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by