Language Reference

ELEMENT Function

ELEMENT (x, y) ;

This function is supported by the IML procedure and the iml action.

The ELEMENT function returns a matrix that is the same shape as x. The return value indicates which elements of x are elements of y. In particular, if A = element(x, y), then

upper A Subscript i Baseline equals StartLayout Enlarged left brace 1st Row 1st Column 1 2nd Column if x Subscript i Baseline element of y 2nd Row 1st Column 0 2nd Column otherwise EndLayout

The arguments are as follows:

x

specifies a matrix of elements to test for membership.

y

specifies a set.

If the intersection between x and y is empty, then the ELEMENT function returns a zero matrix. If x is a proper subset of y, then the ELEMENT function returns a matrix of ones. In general, the ELEMENT function returns 1 for elements in the intersection of x and y, as shown in the following statements:

x = {0, 0.5, 1, 1.5, 2, 2.5, 3, 0.5, 1.5, 3, 3, 1};
set = {0 1 3}`;
b = element(x, set);

n = sum(b);        /* number of elements of X that are in SET */
idx = t(loc(b));   /* indices of elements of X that are in SET */
values = x[idx];   /* values of elements of X that are in SET */
print n idx values;

Figure 141: Elements That Belong to a Set

nidxvalues
610
 31
 73
 103
 113
 121


Last updated: April 11, 2025