How to round a matrix to n decimal places

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

Community Treasure Hunt

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

Start Hunting!

Translated by