How to round a matrix to n decimal places
47 views (last 30 days)
Show older comments
Elanorin Weaving
on 4 Jul 2015
Commented: Yasmin Samy
on 9 May 2019
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?
0 Comments
Accepted Answer
Star Strider
on 4 Jul 2015
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 Comments
Yasmin Samy
on 9 May 2019
Found it!!!
after rounding, convert num2cell and then use
fun3 = @(x) sprintf('%0.3f', x);
More Answers (0)
See Also
Categories
Find more on Graph and Network Algorithms in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!