MATLAB函数取整
Matlab取整函数有: fix, floor, ceil, round.
(1)fix:朝零方向取整,如fix(-1.3)=-1; fix(1.3)=1;
(2)floor:朝负无穷方向取整,如floor(-1.3)=-2; floor(1.3)=1;
(3)ceil:朝正无穷方向取整,如ceil(-1.3)=-1; ceil(1.3)=2;
(4)round:四舍五入到最近的整数,如round(-1.3)=-1;round(-1.52)=-2;round(1.3)=1;round(1.52)=2。
1)fix(x) : 截尾取整.
fix( [4.18 -4.12])
ans =
4 -4
(2)floor(x):不超过x 的最大整数.(高斯取整)
floor( [3.12 -3.12])
ans =
3 -4
(3)ceil(x) : 大于x 的最小整数
ceil( [3.12 -3.12])
ans =
4 -3
(4)四舍五入取整
round([3.12 -3.12])
ans =
3 -3