MATLAB Function Reference Previous page   Next Page
sub2ind

Single index from subscripts

Syntax

Description

The sub2ind command determines the equivalent single index corresponding to a set of subscript values.

IND = sub2ind(siz,I,J) returns the linear index equivalent to the row and column subscripts I and J 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.

IND = sub2ind(siz,I1,I2,...,In) returns the linear index equivalent to the n subscripts I1,I2,...,In for an array of size siz. siz is an n-element vector that specifies the size of each array dimension.

Examples

Create a 3-by-4-by-2 array, A.

The value at row 2, column 1, page 2 of the array is -8.

To convert A(2,1,2) into its equivalent single subscript, use sub2ind.

You can now access the same location in A using the single subscripting method.

See Also

ind2sub, find, size


Previous page  strvcat subplot Next page

© 1994-2005 The MathWorks, Inc.