I want a variable in matlab to store(not to be confused with display) only upto 4 decimal places.
Is there an inbuilt command for it?
I tried the following – but this gives an error:
a = [5.21365458 5.236985475 1.236598547 9.3265874];
k=1;
for i=1:length(a)
ast(k)=sprintf('%5.4f',a(i));
anum(k)=str2num(ast(k));
k=k+1;
end
error is : ??? Subscripted assignment dimension mismatch.
You should round the numbers to four decimal places. This is easy to do in the workspace:
or you could write a function
roundToDP(x,numberOfDecimalPlaces)that does it for you:now you can use that function in the workspace: