MATLAB Function Reference | ![]() ![]() |
Syntax
Definition
Description
M = mod(X,Y)
if Y ~= 0
, returns X - n.*Y
where n = floor(X./Y)
. If Y
is not an integer and the quotient X./Y
is within roundoff error of an integer, then n
is that integer. By convention, mod(X,0)
is X
. The inputs X
and Y
must be real arrays of the same size, or real scalars.
Remarks
So long as operands X
and Y
are of the same sign, the function mod(X,Y)
returns the same result as does rem(X,Y)
. However, for positive X
and Y
,
The mod
function is useful for congruence relationships: x and y are congruent (mod m) if and only if mod(x,m)
== mod(y,m)
.
Examples
See Also
![]() | mlock | more | ![]() |