views:

55

answers:

1

Two matrices, A and B:

A = [1 2 3
     9 7 5
     4 9 4
     1 4 7]

B = [1 2 3
     1 4 7]

All rows of matrix B are members of matrix A. I wish to delete the common rows of A and B from A without sorting.

I have tried setdiff() but this sorts the output.

For my particular problem (atomic coordinates in protein structures) maintaining the ordered integrity of the rows is important.

+7  A: 

Use ISMEMBER:

%# find rows in A that are also in B
commonRows = ismember(A,B,'rows');

%# remove those rows
A(commonRows,:) = [];
Jonas
I LOVE `ismember`! I find uses for it everywhere!
JudoWill