MATLAB Function Reference Previous page   Next Page
ind2sub

Subscripts from linear index

Syntax

Description

The ind2sub command determines the equivalent subscript values corresponding to a single index into an array.

[I,J] = ind2sub(siz,IND) returns the matrices I and J containing the equivalent row and column subscripts corresponding to each linear index in the matrix IND for a matrix of size siz. siz is a 2-element vector, where siz(1) is the number of rows and siz(2) is the number of columns.

[I1,I2,I3,...,In] = ind2sub(siz,IND) returns n subscript arrays I1,I2,...,In containing the equivalent multidimensional array subscripts equivalent to IND for an array of size siz. siz is an n-element vector that specifies the size of each array dimension.

Examples

Example 1. The mapping from linear indexes to subscript equivalents for a 3-by-3 matrix is

This code determines the row and column subscripts in a 3-by-3 matrix, of elements with linear indices 3, 4, 5, 6.

Example 2. The mapping from linear indexes to subscript equivalents for a 2-by-2-by-2 array is

This code determines the subscript equivalents in a 2-by-2-by-2 array, of elements whose linear indices 3, 4, 5, 6 are specified in the IND matrix.

See Also

find, size, sub2ind


Previous page  ind2rgb Inf Next page

© 1994-2005 The MathWorks, Inc.