From: Aris David on
If I have the following matrix and let's say the matrix name is mat and it contains the following elements (5 x 2)

1 2
3 4
5 6
2 1
4 2

How can I write a code to get to delete one of them, where mat(1, 1) = mat(4, 2) and mat(4, 1) = mat(1, 2) as they have similar 1 2 and 2 1

Thanks appreciate your help.
From: us on
"Aris David" <aris.d.david(a)gmail.com> wrote in message <htmmo4$9p2$1(a)fred.mathworks.com>...
> If I have the following matrix and let's say the matrix name is mat and it contains the following elements (5 x 2)
>
> 1 2
> 3 4
> 5 6
> 2 1
> 4 2
>
> How can I write a code to get to delete one of them, where mat(1, 1) = mat(4, 2) and mat(4, 1) = mat(1, 2) as they have similar 1 2 and 2 1
>
> Thanks appreciate your help.

one of the solutions

m=[
1 2
3 4
5 6
2 1
4 2
];
r=unique(sort(m,2),'rows')
%{
% r = % <- note: R is sorted(!)...
1 2
2 4
3 4
5 6
%}

us
From: Nathan on
On May 27, 2:04 pm, "Aris David" <aris.d.da...(a)gmail.com> wrote:
> If I have the following matrix and let's say the matrix name is mat and it contains the following elements (5 x 2)
>
> 1 2
> 3 4
> 5 6
> 2 1
> 4 2
>
> How can I write a code to get to delete one of them,  where mat(1, 1) = mat(4, 2) and mat(4, 1) = mat(1, 2) as they have similar 1 2 and 2 1
>
> Thanks appreciate your help.

A = [1 2;3 4;5 6;2 1;4 2];
[ia ia ia] = intersect(A,fliplr(A),'rows');
A(ia(1),:) = '';
%%%%%%%%%%%
A =
1 2
3 4
5 6
4 2

-Nathan
From: Walter Roberson on
Nathan wrote:
> On May 27, 2:04 pm, "Aris David" <aris.d.da...(a)gmail.com> wrote:
>> If I have the following matrix and let's say the matrix name is mat and it contains the following elements (5 x 2)
>>
>> 1 2
>> 3 4
>> 5 6
>> 2 1
>> 4 2
>>
>> How can I write a code to get to delete one of them, where mat(1, 1) = mat(4, 2) and mat(4, 1) = mat(1, 2) as they have similar 1 2 and 2 1

> A = [1 2;3 4;5 6;2 1;4 2];
> [ia ia ia] = intersect(A,fliplr(A),'rows');
> A(ia(1),:) = '';


And more generally,

[M, M] = unique(sort(A,2),'rows');
B = A(M,:);

This keeps the first unique instance of each row, where "unique" means "has
the same elements in the same quantities".
From: Aris David on
Thank you all. All solutions are fine.