Selectively setting significant digits in display

9 ビュー (過去 30 日間)
ANUBHAV SINHA
ANUBHAV SINHA 2011 年 2 月 5 日
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.

採用された回答

Jiro Doke
Jiro Doke 2011 年 2 月 5 日
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
  1 件のコメント
ANUBHAV SINHA
ANUBHAV SINHA 2011 年 2 月 6 日
Thank you very much Jiro. It helps.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by