Main Content

Convert subscripts to linear indices

returns the linear indices `ind`

= sub2ind(`sz`

,`I1,I2,...,In`

)`ind`

corresponding to multidimensional
subscripts in `n`

arrays `I1,I2,...,In`

for a
multidimensional array of size `sz`

. Here `sz`

is a
vector with `n`

elements that specifies the size of each array
dimension.

For an array `A`

, if `ind = sub2ind(size(A),I1,…,In)`

,
then `A(ind(k)) = A(I1(k),…,In(k))`

for all `k`

.