Reputation: 2249
I'm working on MATLAB. I have the following matrices
A = [
1 2 3 4
5 6 7 8
1 5 2 3
6 7 8 9
1 3 6 2
6 3 1 6
9 7 4 7
];
B = [
1 5 2 3
6 7 8 9
];
I want to find A
-B
so that the answer should be like,
ans = [
1 2 3 4
5 6 7 8
1 3 6 2
6 3 1 6
9 7 4 7
];
Upvotes: 1
Views: 56
Reputation: 112689
@Divakar or @chappjc's answers are the way to go.
But I can't help inviting bsxfun
to the party:
C = A(~any(squeeze(all(bsxfun(@eq, A.', permute(B, [2 3 1])))).'),:);
And its friend pdist2
is coming too:
C = A(all(pdist2(A, B, 'hamming').'),:);
Upvotes: 0
Reputation: 439
clear;
s=0;
A = [
1 2 3 4
5 6 7 8
1 5 2 3
6 7 8 9
1 3 6 2
6 3 1 6
9 7 4 7
];
B = [
1 5 2 3
6 7 8 9
];
for i=1:size(B)
s=s+(ismember(A, B(i,:), 'rows'))
end
A_B = A(s==0,:)
Upvotes: 0