displaying element of matrix

5 ビュー (過去 30 日間)
Eram Khan
Eram Khan 2021 年 5 月 2 日
編集済み: dpb 2021 年 5 月 4 日
How can I display a matrix as output of a function which element are two decimal point based number.
  1 件のコメント
Jonas
Jonas 2021 年 5 月 2 日
if you want to display a matrix you can use disp(matrix)

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

回答 (1 件)

dpb
dpb 2021 年 5 月 2 日
編集済み: dpb 2021 年 5 月 4 日
To use disp and have two decimal points, use format bank first, otherwise will get whatever precision is associated with the current format. Have often thought there should be some ability in disp to have some control over formatting without the full need of fprintf and derived friends.
Otherwise, num2str
disp(num2str(x,'%.2f'))
or, for more control over where placed since disp trims leading blanks in the above
>> format short,format compact
>> disp(A)
240.1400 0.0032
5.0000 3.0000
3.1416 6.0000
6.0000 4.0000
8.0000 0.0000
>> fprintf('%10.2f%10.2f\n',A.')
240.14 0.00
5.00 3.00
3.14 6.00
6.00 4.00
8.00 0.00
>>
General form would be something like
fprintf(repmat('%10.2f',1,size(x,2)) '\n',x.')

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by