Return a matrix tf the same shape as A which has 1 if
A(i,j)
is in S or 0 if it isn't. If a second output argument is requested, the indexes into S of the matching elements are also returned.a = [3, 10, 1]; s = [0:9]; [tf, a_idx] = residue (a, s); tf = [1, 0, 1] a_idx = [4, 0, 2]The inputs, A and S, may also be cell arrays.
a = {'abc'}; s = {'abc', 'def'}; [tf, a_idx] = residue (a, s); tf = [1, 0] a_idx = [1, 0]With the optional third argument
"rows"
, and matrices A and S with the same number of columns, compare rows in A with the rows in S.a = [1:3; 5:7; 4:6]; s = [0:2; 1:3; 2:4; 3:5; 4:6]; [tf, a_idx] = ismember(a, s, 'rows'); tf = logical ([1; 0; 1]) a_idx = [2; 0; 5];