Reputation: 55
In matlab, If an m by 3 matrix has rows that all exist in a bigger n by 3 matrix, how can I create a (n-m) by 3 matrix that does not contain the rows of the first (m by 3) matrix?
e.g. if the first matrix is [1 4 6] and the second matrix [1 2 3; 1 4 6; 8 7 4], how can I come up with the matrix: [1 2 3;8 7 4]?
Upvotes: 2
Views: 230
Reputation: 11168
That's a job for ismember with the 'rows'
option:
a = [1 4 6];
b = [1 2 3; 1 4 6; 8 7 4];
eq_rows = ismember(b,a,'rows');
result = b(~eq_rows,:)
Upvotes: 5