필터 지우기
필터 지우기

Signifcant numbers set in a table

조회 수: 1 (최근 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 CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by