0
votes

I want to find the rows of a matrix which contain specified element of another matrix.

For example, a=[1 2 3 4 5 6 7] and b=[1 2 0 4;0 9 10 11;3 1 2 12]. Now, I want to find the rows of b which contain at least three element of a. For this purpose, I used bsxfun command as following:

c=find(sum(any(bsxfun(@eq, b, reshape(a,1,1,[])), 2), 3)>=3);

It works good for low dimension matrices but when I want to use this for high dimension matrices, for example, when the number of rows of b is 192799, MATLAB gives following error:

Requested 192799x4x48854 (35.1GB) array exceeds maximum array size preference. 
Creation of arrays greater than this limit may take a long time and cause MATLAB 
to become unresponsive. See array size limit or preference panel for more information.

Is there any other command which does this task without producing the behaviour like above for high dimension matrices?

1

1 Answers

2
votes

a possible solution:

a=[1 2 3 4 5 6 7] 
b=[1 2 0 4;0 9 10 11;3 1 2 12]
i=ismember(b,a)
idx = sum(i,2)
idx = find(idx>=3)