index


index, a C code which can convert the index of a multidimensional array entry into the corresponding index of a one dimensional vector, using either row or column major indexing, with zero or unit base.

2D Array Example:

Consider, for example, the following 3x4 array A:

        11 12 13 14
        21 22 23 24
        31 32 33 34
      

Indexing by columns, the array would be stored in a 1D vector as

        11 21 31 | 12 22 32 | 13 23 33 | 14 24 34
      
and the indexing of the elements would be
        11 21 31 | 12 22 32 | 13 23 33 | 14 24 34
         0  1  2    3  4  5    6  7  8    9 10 11  <- zero based
         1  2  3    4  5  6    7  8  9   10 11 12  <- one based
      

Indexing by rows, the array would be stored in a 1D vector as

        11 12 13 14 | 21 22 23 24 | 31 32 33 34
      
and the indexing of the elements would be
        11 12 13 14 | 21 22 23 24 | 31 32 33 34
         0  1  2  3    4  5  6  7   8   9 10 11  <- zero based
         1  2  3  4    5  6  7  8   9  10 11 12  <- one based
      

Licensing:

The computer code and data files described and made available on this web page are distributed under the MIT license

Languages:

index is available in a C version and a C++ version and a FORTRAN90 version and a MATLAB version.

Related Data and Programs:

CELL, a C code which defines a cell array, a generalization of an array which can compactly store and retrieve vector or matrix data of varying size, such as the rows of a triangular matrix.

index_test

Source Code:


Last revised on 09 July 2019.