How to round a matrix to n decimal places

15 ビュー (過去 30 日間)
Elanorin Weaving
Elanorin Weaving 2015 年 7 月 4 日
コメント済み: Yasmin Samy 2019 年 5 月 9 日
Hi,
I am trying to round the matrix to 2 decimal places a=[1.232323 2.23232323; 3.23232323 4.2323232332] round(a,2)
I am getting the error too many input arguments. Is there a work around?

採用された回答

Star Strider
Star Strider 2015 年 7 月 4 日
You can create your own version of the ‘new’ round:
roundn = @(x,n) round(x*10^n)./10^n;
q = roundn(pi,2)
q =
3.14
  5 件のコメント
Yasmin Samy
Yasmin Samy 2019 年 5 月 9 日
Is there no way to round and truncate maybe the numbers?
Yasmin Samy
Yasmin Samy 2019 年 5 月 9 日
Found it!!!
after rounding, convert num2cell and then use
fun3 = @(x) sprintf('%0.3f', x);

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by