%

Modulus operator.

Syntax

expr_1 % expr_2

Operands

expr_1, expr_2
A pair of valid scalar, vector, or matrix expressions.

Example

Expression Result
5 % 2 1
{1, 2, 3} % 2 {1, 0, 1}
5 % {2, 3, 4} {1, 2, 1}
{5, 8, 9} % {6, 6, 6} {5, 2, 3}
{ {1, 2}, {3, 4} } % 2 { {1, 0}, {1, 0} }
{ {5, 6}, {7, 8} } %

{ {1, 2}, {3, 4} }

{ {0, 0}, {1, 0} }

Comments

The modulus operator calculates the remainder of expr_1 divided by expr_2. If both expressions are scalars, the result is the remainder of the quotient of expr_1 / expr_2. expr_2 must not be zero.

If expr_1 is a vector and expr_2 is a scalar, the result is a vector with the same number of elements as expr_1. The elements of the resultant vector are the remainders of the quotients of the corresponding elements of expr_1 and expr_2. expr_2 must be nonzero.

If expr_1 is a scalar and expr_2 is a vector, the result is a vector with the same number of elements as expr_2. The elements of the resultant vector are the remainders of the quotients of expr_1 and the elements of expr_2. Each element of expr_2 must be nonzero.

If expr_1 and expr_2 are vectors with an equal number of elements, the result is a vector with the same number of elements. The elements of the resultant vector are the remainders of the quotients of expr_1 and expr_2. Each element of expr_2 must be nonzero.

If expr_1 is a matrix and expr_2 is a scalar, the result is a matrix with the same dimensions as expr_1. The elements of the resultant matrix are the remainders of the quotients of the corresponding elements of expr_1 and expr_2. expr_2 must be nonzero.

If expr_1 is a scalar and expr_2 is a matrix, the result is a matrix with the same dimensions as expr_2. The elements of the resultant matrix are the remainders of the quotients of expr_1 and the elements of expr_2. Each element of expr_2 must be nonzero.

If expr_1 and expr_2 are matrices with equal dimensions, the result is a matrix with the same dimensions. The elements of the result are the corresponding remainders of the quotients of the corresponding elements of expr_1 and expr_2. Each element of expr_2 must be nonzero.