MATLAB: How to get the length of the intersection of each row of a matrix with another vector

findintersectlengthmatrixvector

This is my scenario:
C = combnk(1:5, 3)
C =
1 2 3
1 2 4
1 2 5
1 3 4
1 3 5
1 4 5
2 3 4
2 3 5
2 4 5
3 4 5
And:
V =
2 3
I need a new matrix with each row having the length of the intersection of each row of C with vector V, like this:
R =
2
1
1
1
1
0
2
2
1
1
Ideally I would like a new matrix that is a filtered C in which the resulting intersection length passes a given condition.
Sorry if this is pretty basic stuff, I don't seem to find the way to do it. Thanks!

Best Answer

Method one: ismember:
>> sum(ismember(C,V),2)
ans =
2
1
1
1
1
0
2
2
1
1
Method two: reshape and ==:
>> sum(sum(C==reshape(V,1,1,[]),3),2)
ans =
2
1
1
1
1
0
2
2
1
1
Method three: histc:
>> sum(histc(C,V,2),2)
ans =
2
1
1
1
1
0
2
2
1
1