Check for subset

Test if vector elements are a subset of another vector.

% subset of numerical vectors

a = [2,3,4,5,6]

b = [3,5]

% is 'b' a subset of 'a' ?

all(ismember(b, a))

1 % True (yes is subset)

% subset of logical vectors

% use find when comparing logical index vectors

x=[1,2,3,4,5,6,7,8]

idxA= x > 3

0 0 0 1 1 1 1 1

idxB= x > 5

0 0 0 0 0 1 1 1

% is logical vector idxB a subset of idxA ?

all(ismember(find(idxB), find(idxA)))

1 % True (yes is subset)