FreeMat

- Main Page
- Related Pages

IND2SUB Convert Linear Indexing To Multiple Indexing

Section: Elementary Functions

# Usage

The `ind2sub` function converts linear indexing expression into a multi-dimensional indexing expressionl The syntax for its use is

       [d1, d2, ..., dn] = ind2sub(sizevec,index)

where `sizevec` is the size of the array being indexed into, index is the index value. Each `di` is a vector of the same length, containing index values.

# Example

Suppose we have a simple `3 x 4` matrix `A` containing some random integer elements

    --> A = randi(ones(3,4),10*ones(3,4))

    A =
      6  6  9  6
     10  1  8  6
      9  1  6  2

    --> [d1 d2] = ind2sub(size(A),7)
    d1 =
     1

    d2 =
     3

    --> A(d1,d2)

    ans =
     9