matlab里面的取整函数(fix,round,floor……

在对数据进行处理时,有时我们需要对含有小数的数据进行取整处理,本例分享matlab里面常用的几种取整函数,fix、round、floor、ceil

操作方法

(01)fix-向零方向取整。fix    Round towards (X) rounds the elements of X to the nearest integerstowards zero.

(02)fix使用举例:t =7.6806    3.5388    3.6130    9.0150    8.1769    3.17812.3309    3.4719    7.4163    3.1834    9.8118    9.84455.8736    2.5372    7.0590    5.9708    8.6199    5.48254.5897    9.5253    7.0089    2.9780    0.8382    7.49258.6098    2.9820    0.0623    1.2501    3.3771    8.41856.6084    1.5841    3.7435    3.8836    2.3613    1.6689-----------------------------------------------------------------------fix(t)ans =7     3     3     9     8     32     3     7     3     9     95     2     7     5     8     54     9     7     2     0     78     2     0     1     3     86     1     3     3     2     1

matlab里面的取整函数(fix,round,floor……

(03)round-向最近的方向取整。round  Round towards nearest d(X) rounds the elements of X to the nearest integers.

matlab里面的取整函数(fix,round,floor…… 第2张

(04)floor-向负无穷大方向取整:floor  Round towards minus r(X) rounds the elements of X to the nearest integerstowards minus infinity.

matlab里面的取整函数(fix,round,floor…… 第3张

(05)ceil-向正无穷大方向取整。ceil   Round towards plus (X) rounds the elements of X to the nearest integerstowards infinity.

matlab里面的取整函数(fix,round,floor…… 第4张

(06)mod-计算模数:mod    Modulus after (x,y) is x - n.*y where n = floor(x./y) if y ~= 0.  If y is not aninteger and the quotient x./y is within roundoff error of an integer,then n is that integer.  The inputs x and y must be real arrays of thesame size, or real statement "x and y are congruent mod m" means mod(x,m) == mod(y,m) convention:mod(x,0) is (x,x) is (x,y), for x~=y and y~=0, has the same sign as : REM(x,y), for x~=y and y~=0, has the same sign as (x,y) and REM(x,y) are equal if x and y have the same sign, butdiffer by y if x and y have different signs.

matlab里面的取整函数(fix,round,floor…… 第5张

特别提示

rem函数可以计算余数(真实的余数,可以是任意实数)