sub2ind
Convert N-dimensional subscripts to a single linear index.
Syntax
Section titled “Syntax”IND = sub2ind(siz, I1, I2, ...)Description
Section titled “Description”Given a size vector siz and one subscript per dimension (I1, I2, …), returns the corresponding 1-based linear (column-major) index. Useful for converting (row, col) or (i, j, k) references into a single index suitable for vector-style indexing.
MathJet’s implementation accepts only scalar subscripts (one index value per dimension). The MATLAB-style array form — passing matched arrays of subscripts — is not yet supported.
Examples
Section titled “Examples”sub2ind([3 4], 2, 3) % 8 (row 2, col 3 of a 3×4 matrix)A = magic(3); A(sub2ind([3 3], 2, 3)) % same as A(2,3)