mod 函数
Modulus after division
余数(除法运算后的系数或称为有符号取余)
Syntax
语法
M = mod(X,Y)
Definition
定义
mod(x,y) is mod .
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.
M=mod(X,Y)如果Y~=0,返回X-n.*y这里的n=floor(X./Y)。如果Y不是一个整数并且商X./Y是一个整数的内部错误,之后n是整数。通过被约束,mod(X,0)是X。输出的X和Y必须是相同大小的实数阵列,或是实数数量。
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,
再次遇到具有相同迹象的操作数X和Y,函数mod(X,Y)返回相同的结果为rem(X,Y)。无论如何,正数X和Y,
mod(-X,Y) = rem(-X,Y)+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).
mod函数对一致关系是很有用处的:x和y是一致(mod m)如果并且仅仅如果mod(x,m)=mod(y,m)。
Examples
例如:
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