sub2ind

Converts subscript to a linear index. From dimensions x and index i,j.

Syntax

ind = sub2ind(dim,i,j)

Inputs

dim
Matrix dimensions.
Type: double | integer
Dimension: scalar | string | vector | matrix
i,j
2-dimensional indices.
Type: double | integer | char | string | logical | struct | cell
Dimension: scalar | string | vector | matrix

Outputs

ind
Linear index.

Example

Simple sub2ind example.

sub2ind([2,4;5,2],2,5)
ans = 10