Section: Mathematical Functions
y = rem(x,n)
where x is matrix, and n is the base of the modulus. The
effect of the rem operator is to add or subtract multiples of n
to the vector x so that each element x_i is between 0 and n
(strictly). Note that n does not have to be an integer. Also,
n can either be a scalar (same base for all elements of x), or a
vector (different base for each element of x).
Note that the following are defined behaviors:
rem(x,0) = nan@
rem(x,x) = 0@ for nonzero x
rem(x,n)@ has the same sign as x for all other cases.
rem and mod return the same value if x and n
are of the same sign. But differ by n if x and y have
different signs.
rem
arrays.
--> rem(18,12) ans = <double> - size: [1 1] 6 --> rem(6,5) ans = <double> - size: [1 1] 1 --> rem(2*pi,pi) ans = <double> - size: [1 1] 0
Here is an example of using rem to determine if integers are even
or odd:
--> rem([1,3,5,2],2) ans = <double> - size: [1 4] Columns 1 to 4 1 1 1 0
Here we use the second form of rem, with each element using a
separate base.
--> rem([9 3 2 0],[1 0 2 2]) ans = <double> - size: [1 4] Columns 1 to 4 0 nan 0 0