ELEMENT
(x, y) ;
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
|
The arguments are as follows:
specifies a matrix of elements to test for membership.
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 23.108: Elements That Belong to a Set
n | idx | values |
---|---|---|
6 | 1 | 0 |
3 | 1 | |
7 | 3 | |
10 | 3 | |
11 | 3 | |
12 | 1 |