Logical Addressing

 

The relational operators >, >=, <, <=, and == return a logical result, a scalar, series, or array whose elements are either 1 (true) or 0 (false).

 

a = 1..10;

b = a > 5;

 

The expression a > 5 produces the logical series:

 

b == {0, 0, 0, 0, 0, 1, 1, 1, 1, 1}

 

Using Logical Values as Indices

 

A logical series can be used directly to index another series:

 

c = a[b]

 

Result:

 

c == {6, 7, 8, 9, 10}

 

Wherever b is 1, the corresponding element of a is selected; wherever b is 0, the element is ignored.

 

This is equivalent to:

 

c = a[a > 5]

 

and also to:

 

c = a[find(a > 5)]

 

The LOGICAL function will convert a series to a logical series by setting the output element to 1 where the input element is nonzero and setting the output element to 0 wherever the input element is 0.

 

The ISLOGICAL function returns 1 if the input is a logical scalar,  series or array, else it returns 0.