IND2SUB

Purpose:

Converts linear (unraveled) indices to row-column subscripts.

Syntax:

IND2SUB(nr, nc, np, ind)

(row, col) = IND2SUB(nr, nc, ind)

(row, col, page) = IND2SUB(nr, nc, np, ind)

 

nr

-

An integer. The number of rows.

nc

-

An integer. The number of columns.

np

-

Optional. An integer, the number of 3D pages. Defaults to 1.

ind

-

A series, the linear indices.

 

Alternate Syntax:

IND2SUB(sz, ind)

(row, col) = IND2SUB(sz, ind)

(row, col, page) = IND2SUB(sz, ind)

 

sz

-

A series, where the values specify the number of rows, columns and optional pages.

ind

-

A series, the linear indices.

Returns:

An integer series of linear array indices.

 

(row, col) = IND2SUB(nr, nc, ind) and (row, col) = IND2SUB(sz, ind) returns the row and column subscripts as two separate series.

 

(row, col, page) = IND2SUB(nr, nc, np, ind) and (row, col, page) = IND2SUB(sz, ind) returns the row, column and page subscripts as three separate series.

Example:

W1: magic(10);table

W2: {W1[26]}

W3: ind2sub(numrows(w1), numcols(w1), 26)

W4: w1[col(w3, 1), col(w3, 2)]

 

W1 contains a 10x10 magic array where the sum of each column is equal to the sum of each row.

 

W2 contains {76}, the value of W1 at index 26.

 

W3 converts the linear array index 26 to array subscripts {{6, 3}}.

 

W4 returns {76}, the value of W1 at row 6, column 3, the same as W2, the value of W1 at index 26.

Example:

W1: magic(10)

W2: {W1[26]}

W3: (r, c) = ind2sub(size(w1), 26);{W1[r, c]}

 

Same as above, except SIZE is used in W3 to specify the number of rows and columns and the row and column values are returned in two separate variables.

Example:

W1: 10 * ravel(1..100, 5);table

W2: ind2sub(5, 2, 10, {38})

W3: w1[sub2ind(5, 2, 10, w2)]

 

W1 contains a 5x20 array.

 

W2 considers W1 to be a 3D array of size 5x2x10. The linear index of 38 is converted to subscript row 3, column 2, page 4 as the series {{3, 2, 4}}.

 

W3 uses SUB2IND to convert the subscripts in W2 to a linear index. The result is 280, the value of W1 at index 38.

Remarks:

IND2SUB converts linear or unraveled array indices to subscripts in row column form.

 

See SUB2IND to convert array subscripts in row column form to linear or unraveled indices.

See Also:

REORDER

IDXTODT

IDXTOX

SUB2IND

XTODT

XTOIDX