Navigation

Operators and Keywords

Function List:

C++ API

: tf = ismember (a, s)
: tf = ismember (a, s, "rows")
: [tf, s_idx] = ismember (…)

Return a logical matrix tf with the same shape as a which is true (1) if the element in a is found in s and false (0) if it is not.

If a second output argument is requested then the index into s of each matching element is also returned.

a = [3, 10, 1];
s = [0:9];
[tf, s_idx] = ismember (a, s)
     ⇒ tf = [1, 0, 1]
     ⇒ s_idx = [4, 0, 2]

The inputs a and s may also be cell arrays.

a = {"abc"};
s = {"abc", "def"};
[tf, s_idx] = ismember (a, s)
     ⇒ tf = [1, 0]
     ⇒ s_idx = [1, 0]

If the optional third argument "rows" is given then compare rows in a with rows in s. The inputs must be 2-D matrices with the same number of columns to use this option.

a = [1:3; 5:7; 4:6];
s = [0:2; 1:3; 2:4; 3:5; 4:6];
[tf, s_idx] = ismember (a, s, "rows")
     ⇒ tf = logical ([1; 0; 1])
     ⇒ s_idx = [2; 0; 5];

See also: lookup, unique, union, intersect, setdiff, setxor.

Package: octave