| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → MATLAB |
| Contents | Index |
| Learn more about MATLAB |
M = mod(X,Y)
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. The inputs X and Y must be real arrays of the same size, or real scalars.
The following are true by convention:
mod(X,0) is X
mod(X,X) is 0
mod(X,Y) for X~=Y and Y~=0 has the same sign as Y.
rem(X,Y) for X~=Y and Y~=0 has the same sign as X.
mod(X,Y) and rem(X,Y) are equal if X and Y have the same sign, but differ by Y if X and Y have different signs.
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).
mod(13,5)
ans =
3
mod([1:5],3)
ans =
1 2 0 1 2
mod(magic(3),3)
ans =
2 1 0
0 2 1
1 0 2![]() | mmreader.isPlatformSupported | mode | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |