ind2sub

Returns subscript from the linear index ind.

Syntax

[i,j]=ind2sub(dim, ind)

Inputs

dim
Matrix dimensions.
Type: double | integer
Dimension: scalar | string | vector | matrix
ind
Linear index.
Type: double | integer
Dimension: scalar

Outputs

i,j
2-dimensional indices.

Example

Simple ind2sub example:

[i,j]=ind2sub([4,5], 7)
i = 3
j = 2