MATLAB: Find row with certain values

findsearch

Hello I am looking for a (simple) way to get the index of a row in which two (or n) values exist
example: looking for 4 and 5 in
[1 5 6; 5 4 3; 9 4 2]
will give me 2, because only row 2 has both 4 and 5 in it
Thanks
Daniel

Best Answer

similar to the intersect answer - but I recoded intersect as its quite slow:
x=[1 2 3;4 5 6;3 2 1];
[a b]=find(x==4);
[c d]=find(x==5);
index = c.*NaN;
for kk=1:length(c)
check = a(a==c(kk))';
if ~isempty ( check )
index(kk) = check;
end
end
output = index(~isnan(index));