Converts subscripts to a linear index.
The function accepts the following "modes":
throw
wrap
clamp
0
If provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.
first argument must be an array-like object containing nonnegative integers
subscripts must be integer valued
must provide valid options
must provide subscripts which do not exceed array dimensions
number of subscripts much match the number of dimensions
array shape
subscripts followed by an optional options object
linear index
var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); // returns 17
Converts subscripts to a linear index.
Notes
The function accepts the following "modes":
throw
: throws an error when a subscript exceeds array dimensions.wrap
: wrap around subscripts exceeding array dimensions using modulo arithmetic.clamp
: set subscripts exceeding array dimensions to either0
(minimum index) or the maximum index along a particular dimension.If provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.
first argument must be an array-like object containing nonnegative integers
subscripts must be integer valued
must provide valid options
must provide subscripts which do not exceed array dimensions
number of subscripts much match the number of dimensions