# selif¶

## Purpose¶

Selects rows from a matrix. Those selected are the rows for which there is a 1 in the corresponding row of e.

## Format¶

y = selif(x, e)
Parameters: x (NxK matrix or string array) – data e (vector) – Nx1 vector of 1’s and 0’s y (MxK matrix or string array) – consists of the rows of x for which there is a 1 in the corresponding row of e.

## Examples¶

x = { 112 252,
99 119,
109  81,
184 111,
209  94 };

y = selif(x, x[., 2] .> 100);


This example selects all rows of x in which the second column is greater than 100. This will set y equal to:

112    252
99    119
184    111

x = { 0 10 20,
30 40 50,
60 70 80 };

e = (x[., 1] .gt 0) .and (x[., 3] .< 100);
y = selif(x, e);


The resulting matrix y is:

30 40 50
60 70 80


All rows for which the element in column 1 is greater than 0 and the element in column 3 is less than 100 are placed into the matrix y.

## Remarks¶

The argument e will usually be generated by a logical expression using “dot” operators.

y will be a scalar missing if no rows are selected.