MATLAB: How to round a matrix to n decimal places

rounding matrix 2 decimal places

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?

Best Answer

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