I have a matrix A of size Nx2, N is large. I have another vector b of size nx1 and n<<N. I want to filter out those row indices of A, where both columns could contain any 2 elements of b.
For instance, let
A = [1 2;3 4; 5 6]
b = [1,2,5,6]'
Then output of method(A,b) should be
(i.e. the first and 3rd rows of A contain 2 elements from b, but not the 2nd row.
I am currently using a combination of ismember and find but seems like ismember is not very efficient because my A, as I said, is very large.
Thanks in advance!
EDIT: (some more background on the problem)
The code has about couple dozen functions of which couple of them call ismember within a loop. The overall code takes several hours to execute when N is in O(1e5) and profiling it showed most of the time is consumed by ismember. The whole point of the question is to verify if (i) ismember is specifically inefficient for large scale code and (ii) are there alternatives that could take only a fraction of ismember 's cputime
EDIT 2: Tried alternative suggestion using 'any'. The cpu time was almost identical.
EDIT 3: Solved. Based on my personal experience, it does seem like ismember is inefficient when used repeatedly used within a large loop. So I replaced it with cellfun (since my 'b' is actually a cell array) & bsxfun and saw 25x speedup. Thanks to everyone that chimed in. I learned a lot!