Signifcant numbers set in a table

2 ビュー (過去 30 日間)
Ali razi
Ali razi 2021 年 2 月 1 日
回答済み: Adam Danz 2021 年 2 月 1 日
Can anyone please give an advice how to set the significant numbers only on the table numerical fields?
Code:
clc;
clear all;
xID = ['1';'2';'3';'4';'5'];
xName = {'Sun';'Moon';'Jupiter';'Earth';'Venus'};
I1 = [1.1112;9.2311245;3.341145;6.341122;54.211155];
I2 = [1.1199999;1.1211345;1.881188;1.5781188;1.63711777];
I3 = [6.232114;5.1211223654;4.452112272;3.5711235;2.62112247];
mt = table(xID, xName, I1, I2, I3);
table_data=cellfun(@(x) sprintf('%0.2f', x), mt), 'UniformOutput',0);
  4 件のコメント
Ali razi
Ali razi 2021 年 2 月 1 日
編集済み: Ali razi 2021 年 2 月 1 日
I wish to show it using matlab report and not for display issues.
dpb
dpb 2021 年 2 月 1 日
What, specifically, do you mean by " using matlab report"?

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

採用された回答

Adam Danz
Adam Danz 2021 年 2 月 1 日
This example shows how to permanently round the data to 2dp which is usually undesirable but if you're printing it to a report, it's not like the level of precision can be edited anyway.
Use varfun to determine which columns are numeric.
colIsNum = varfun(@isnumeric, mt,'OutputFormat','uniform')
ans =
1×5 logical array
0 0 1 1 1
table_data = mt; % keep original, more precise data
table_data{:,colIsNum} = round(mt{:,colIsNum},2)
table_data =
5×5 table
xID xName I1 I2 I3
___ ___________ _____ ____ ____
1 {'Sun' } 1.11 1.12 6.23
2 {'Moon' } 9.23 1.12 5.12
3 {'Jupiter'} 3.34 1.88 4.45
4 {'Earth' } 6.34 1.58 3.57
5 {'Venus' } 54.21 1.64 2.62

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

タグ

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by