[TOC]

sub2ind

Converting subscripts to linear index

Usage

I = sub2ind(sizVec, sub1, sub2, ..., subN)

sub2ind

Example

Input
I1 = randi(10,1,5)
[s1, s2] = ind2sub([2 5], I1)
I2 = sub2ind([2 5], s1, s2)
Output
I1 = 
 3.0000   3.0000   4.0000   10.000   4.0000

s1 = 
 1.0000   1.0000   2.0000   2.0000   2.0000

s2 = 
 2.0000   2.0000   2.0000   5.0000   2.0000

I2 = 
 3.0000   3.0000   4.0000   10.000   4.0000