MATLAB: Finding a vector as a subset of an array

arraysubset

I have
a = [2 2];
b = [2 3];
How to find that 'b' contains all the elements of 'a' i.e. here two 2's. Here 'b' contains only one '2'.

Best Answer

[u,~,j] = unique(a(:));
[tf,loc] = ismember(b(:),u);
s = [length(u),1];
result = all(accumarray(j(:),1,s) <= accumarray(loc(tf),1,s))