MATLAB Truncated Variable

I am working with an array Ain MATLAB. Values ​​in this array have up to 5 decimal places. I would like to trim these values ​​to fewer decimal places.

Is there any way to do this?

Thank!

0
source share
2 answers

For some reason, the "truncate" function of Matlab is called fix. So

>> fix(3.5) 
ans = 3

>> fix(-3.5)
ans = -3

To truncate, round, gender, or place something by a given number of decimal places, multiply by decimal numbers, truncate, circle, gender, or gender, and then divide the result by dozens.

So:

>> fix(123.456 * 10^2)
ans = 12345

>> ans / 10^2
ans = 123.45
+1
source

Rounding numbers:

( ) , round, , ...

round(1.2345, 2) 

ans = 1.2300

, shortg

format shortg

round(1.2345, 2)

ans = 1.23

compact , , , .

:

: https://uk.mathworks.com/help/matlab/ref/round.html

: https://uk.mathworks.com/help/matlab/ref/format.html

+3

Source: https://habr.com/ru/post/1684339/


All Articles