Search code examples
arraysmatlabmember

Find rows in B not in A


Matrix A(100,3) and B(1000,3). I want to obtain 1) rows in B that are not in A with their indices, 2) rows in B & present in A with their indices.

A=randi([1 5],100,3)
B=randi([1 5],1000,3)
[a b]=intersect(A,B)
[c d]=~intersect(A,B)

How to put it so that row indices will be obtained.


Solution

  • You can use setdiff and intersect with the 'rows' option:

    [inBnotA, inBnotAindex] = setdiff(B, A, 'rows');
    [inBandA, inBandAindex] = intersect(B, A, 'rows');