Language Reference


REMOVE Function

REMOVE (matrix, indices);

The REMOVE function discards elements from a matrix. The arguments to the REMOVE function are as follows:

matrix

is a numeric or character matrix or literal.

indices

specifies the indices of elements of matrix to remove.

The REMOVE function returns (as a row vector) a subset of the elements of the first argument. Elements that correspond to indices in the second argument are removed. The elements of the first argument are enumerated in row-major order, and the indices must be in the range 1 to $np$, where matrix is an $n\times p$ matrix. Nonintegral indices are truncated to their integer part. You can repeat the indices and give them in any order. If all elements are removed, the result is an empty matrix with zero rows and zero columns.

The following statements remove the third element, creating a row vector with three elements:

x = {5 6, 7 8};
a = remove(x, 3);      /* remove element 3 */
print a;

Figure 25.325: Result of Removing an Element

a
5 6 8



The following statements remove all but the fourth element:

r = {3 2 3 1};
b = remove(x, r);      /* equivalent to removing elements 1:3 */
print b;

Figure 25.326: Result of Removing Several Elements

b
8



The output shown in FigureĀ 25.326 shows that repeated indices are ignored.