sub2ind
Converts subscript to a linear index.
Syntax
ind = sub2ind(dim,i,j)
ind = sub2ind(dim,s1,s2,...,sn)
Inputs
- dim
- Matrix dimensions.
- i,j
- 2-dimensional indices.
- s1,s2,...,sn
- N-dimensional indices.
Outputs
- ind
- Linear index.
Examples
Simple sub2ind example.
sub2ind([2,4;5,2],2,5)
ans = 10
sub2ind example with a 3-dimensional matrix of size 2x5x3
mat3D = randn(2,5,3);
sub2ind(size(mat3D),2,3,1)
ans = 6