C/C++取整函數:
函數名 |
功能說明 |
舉例說明 |
floor() |
向負無窮大舍入(向下取整) |
floor(-10.5) == -11 floor(10.5)==10 |
ceil() |
向正無窮大舍入(向上取整) |
ceil(-10.5) == -10 ceil(10.5)==11 |
RoundEx() |
向最接近的整數取整(四捨五入) |
RoundEx(2.3)==2 RoundEx(2.6)==3 |
MATLAB取整函數:
函數名 | 功能說明 | 舉例說明 |
---|---|---|
round(x) | x向最接近的整數取整(四捨五入) |
round(4.2)=4 round(4.5)=5 |
fix(x) | x向0方向取整 |
fix(4.2)=4 fix(4.5)=4 |
floor(x) | x向下取整 |
floor(4.2)=4 floor(4.5)=4 |
ceil(x) | x向上取整 |
ceil(4.2)=5 ceil(4.5)=5 |
可以看出在C和C++裏面常用到的取整函數,在MATLAB裏邊都有,特別注意C/C++裏邊的四捨五入取整函數RoundEx()在MATLAB裏邊的表示方法爲round()。