previousindex

Purpose

Returns the index of the previous element or subarray in an array.

Format

pi = previousindex(i, orders)
Parameters:
  • i (Mx1 vector) – indices into an array where \(M <= N\).

  • orders (Nx1 vector) – orders of an N-dimensional array

Returns:

pi (Mx1 vector of indices) – the index of the previous element or subarray in the array corresponding to orders.

Examples

// Set orders
orders = { 3, 4, 5, 6, 7 };

// Initialize array
a = areshape(1, orders);

// Get orders of the array
orders = getorders(a);

// Set starting index
ind = { 2, 3, 1 };

// Get previous index
pi = previousindex(ind, orders);

After the code above, pi is equal to:

      2
pi =  2
      5

In this example, previousindex() decremented pi to index the previous 6x7 subarray in array a.

Remarks

previousindex() will return a scalar error code if the index cannot be decremented.

See also

Functions nextindex(), loopnextindex, walkindex()