MATLAB: Find a vector in a big vector

find statement in matlab

hi! how could i write this:
%
index=[find(a=2);find(a=4);find(a=6);find(a=8)....find(a=20)]
in a compact manner?
thank you

Best Answer

vals = (2:2:20)';
your_mat = cell2mat(arrayfun(@(x) {find(a==x)},vals,'uniformoutput',false));
And if you don't care about the order:
vals = (2:2:20)';
[ia ib] = ismember(a,vals);