The REM () and mod () functions of MATLAB
REM (x, y): to divide the remainder of X/y
MoD (x, y): modulo
REM (x, y) =x-y.*fix (x./y); (fix () rounding to 0)
MoD (x, y) =x-y.*floor (x./y); (Floor () rounding left)
If x and y are the same symbol (same as ' + ', same as '-'), then REM (x, y) =mod (x, y) (positive and positive, negative and negative, rounding results two function effects)
If the sign of x and Y is reversed, then mod (x, y) =rem (x, y) +y (positive and negative numbers are rounded to see what you want to do with the function you choose)
When the positive and negative values are taken, the sign of the resulting remainder is expected to be the same as the divisor (x), with the REM () function; When the resulting remainder of the symbol wants to be the same as the divisor (y), use the MoD () function
For example:
REM (3,2) =1;mod (3,2) = 1;
REM ( -3,-2) =-1;mod ( -3,-2) =-1;
REM (3,-2) =1;mod (3,-2) =-1;
REM ( -3,2) =-1;mod ( -3,2) = 1;
MoD (3,2) =rem (3,2) = 1;
MoD (3,-2) =rem (3,-2) -2=1-2=-1;
MoD ( -3,2) =rem ( -3,2) +2=-1+2=1;
The REM () and mod () functions of MATLAB