当前位置:   article > 正文

MATLAB中的取整函数(fix、round、floor、ceil)_nearest(convergent)

nearest(convergent)
  • fix - 向零方向取整

fix Round towards zero.
    fix(X) rounds the elements of X to the nearest integers towards zero.

例:

t =

7.6806 3.5388 3.6130
2.3309 3.4719 7.4163
5.8736 2.5372 7.0590

fix(t)

ans =

7 3 3
2 3 7
5 2 7

  • round - 向最近的方向取整,亦即“四舍五入”

round rounds towards nearest decimal or integer
    round(X) rounds each element of X to the nearest integer.

例:

t =

7.6806 3.5388 3.6130
2.3309 3.4719 7.4163
5.8736 2.5372 7.0590

round(t)

ans =

8 4 4
2 3 7
6 3 7

  • floor - 向负无穷大方向取整

floor Round towards minus infinity.
    floor(X) rounds the elements of X to the nearest integers towards minus infinity.

例:

t =

7.6806 3.5388 3.6130
2.3309 3.4719 7.4163
5.8736 2.5372 7.0590

floor(t)

ans =

7 3 3
2 3 7
5 2 7

  • ceil - 向正无穷大方向取整

ceil Round towards plus infinity.
    ceil(X) rounds the elements of X to the nearest integers towards infinity.

t =

7.6806 3.5388 3.6130
2.3309 3.4719 7.4163
5.8736 2.5372 7.0590

ceil(t)

ans =

8 4 4
3 4 8
6 3 8

nearest

    CONVERGENT, nearest, and ROUND only differ in the way they treat
    values whose fractional part is 0.5.
 
    In CONVERGENT, the ties are rounded to the nearest even integer. 
    In nearest, the ties are rounded up.
    In ROUND, the ties are rounded up if positive, and down if negative.

>>   [x convergent(x) nearest(x) round(x) fix(x)]

ans =

   -3.5000   -4.0000   -3.0000   -4.0000   -3.0000
   -2.5000   -2.0000   -2.0000   -3.0000   -2.0000
   -1.5000   -2.0000   -1.0000   -2.0000   -1.0000
   -0.5000         0         0   -1.0000         0
    0.5000         0    1.0000    1.0000         0
    1.5000    2.0000    2.0000    2.0000    1.0000
    2.5000    2.0000    3.0000    3.0000    2.0000
    3.5000    4.0000    4.0000    4.0000    3.0000

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/运维做开发/article/detail/960996
推荐阅读
相关标签
  

闽ICP备14008679号