Round all values in table

44 ビュー (過去 30 日間)
Dion Theunissen
Dion Theunissen 2021 年 10 月 25 日
編集済み: Scott MacKenzie 2021 年 10 月 25 日
Hi,
I have a table with calculated values. Now I want to round all values to 2 decimals. How can I do that in once for the whole table?

回答 (1 件)

Scott MacKenzie
Scott MacKenzie 2021 年 10 月 25 日
編集済み: Scott MacKenzie 2021 年 10 月 25 日
I think this achieves what you are after:
% test data
T1 = array2table(rand(5))
T1 = 5×5 table
Var1 Var2 Var3 Var4 Var5 _________ _______ _______ ________ ________ 0.0024079 0.97172 0.41667 0.027209 0.079337 0.14919 0.17995 0.58257 0.46413 0.99968 0.56165 0.79083 0.06821 0.18682 0.23824 0.31412 0.6835 0.82666 0.49151 0.12438 0.78186 0.66873 0.07059 0.86243 0.32011
% rounded to 2 decimal places
T2 = array2table(round(T1{:,:},2))
T2 = 5×5 table
Var1 Var2 Var3 Var4 Var5 ____ ____ ____ ____ ____ 0 0.97 0.42 0.03 0.08 0.15 0.18 0.58 0.46 1 0.56 0.79 0.07 0.19 0.24 0.31 0.68 0.83 0.49 0.12 0.78 0.67 0.07 0.86 0.32

カテゴリ

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

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by