ind2sub
Convert linear indices to subscripts
Description
[
returns I1,I2,...,In] = ind2sub(sz,ind)n arrays I1,I2,...,In containing the
equivalent multidimensional subscripts corresponding to the linear indices
ind for a multidimensional array of size sz. Here
sz is a vector with n elements that specifies the
size of each array dimension.
Examples
Input Arguments
Output Arguments
Tips
To get the linear indices of matrix elements that satisfy a specific condition for matrix
A, you can use thefindfunction with one output argument. To get the subscript indices, use thefindfunction with two output arguments. For example,[row,col] = ind2sub(size(A),find(A>5))gives the same result as[row,col] = find(A>5).
Algorithms
For an array A, if [I1,…,In] = ind2sub(size(A),ind),
then A(I1(k),…,In(k)) = A(ind(k)) for all k.

