MATLAB: How to compare rows from two arrays and delete the different column

compare arraydelete array

Hello Everyone,
if true
% code


end
I have two array Arr1 = 1 2 6
2 4 8
5 6 4
8 1 10
if true
% code
endand I have another Arr2 = 1 2 3
2 3 4
5 6 7
8 9 10
11 12 13
I want to remove the common elements from both arrays
so my result should look like
if true
% code
end Arr1 = 1 2 6
5 6 4
Arr2 = 1 2 3
5 6 7
How can I solve this problem

Best Answer

Maybe use ismember() with the rows option:
Arr1 = [1 2 6;
2 4 8;
5 6 4;
8 1 10]
Arr2 = [1 2 3;
2 3 4;
5 6 7;
8 9 10;
11 12 13]
[ia, ib] = ismember(Arr1(:, 1:2), Arr2(:, 1:2), 'rows')
Arr1 = Arr1(ia, :)
Arr2 = Arr2(ia, :)
You'll see in the command window:
ia =
4×1 logical array
1
0
1
0
ib =
1
0
3
0
Arr1 =
1 2 6
5 6 4
Arr2 =
1 2 3
5 6 7