Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
remove row if it is 'mirrored'

Subject: remove row if it is 'mirrored'

From: Natalie Sin Hwee

Date: 20 Jul, 2010 13:29:22

Message: 1 of 4

Dear Mathwork users,
I have a 6000x2 matrix:

     1 88
     1 67
     2 31
     2 30
     2 88
     2 65
     3 31
     3 61
     3 71
     3 79

etc.

and sometimes the rows will have 'mirrored' similarities
eg.

     1 88

and further down...
     88 1

In this case, is there any suggestions to remove the second pair (i.e. 88 1) because they are practically the same from node1->88 and node 88->1

^^ thank you lots ^^
Natalie :)

Subject: remove row if it is 'mirrored'

From: Wayne King

Date: 20 Jul, 2010 13:43:04

Message: 2 of 4

"Natalie Sin Hwee " <sin.ng09@imperial.ac.uk> wrote in message <i248bi$n9k$1@fred.mathworks.com>...
> Dear Mathwork users,
> I have a 6000x2 matrix:
>
> 1 88
> 1 67
> 2 31
> 2 30
> 2 88
> 2 65
> 3 31
> 3 61
> 3 71
> 3 79
>
> etc.
>
> and sometimes the rows will have 'mirrored' similarities
> eg.
>
> 1 88
>
> and further down...
> 88 1
>
> In this case, is there any suggestions to remove the second pair (i.e. 88 1) because they are practically the same from node1->88 and node 88->1
>
> ^^ thank you lots ^^
> Natalie :)

Hi Natalie, One of many ways:

 X = [1 88
     1 67
     2 31
     2 30
     2 88
     2 65
     3 31
     3 61
     3 71
     3 79
     88 1];
[C,IA,IB] = intersect(X,fliplr(X),'rows');
X(IA(2),:)=[];

Hope that helps,
Wayne

Subject: remove row if it is 'mirrored'

From: Sean

Date: 20 Jul, 2010 13:49:04

Message: 3 of 4

"Natalie Sin Hwee " <sin.ng09@imperial.ac.uk> wrote in message <i248bi$n9k$1@fred.mathworks.com>...
> Dear Mathwork users,
> I have a 6000x2 matrix:
>
> 1 88
> 1 67
> 2 31
> 2 30
> 2 88
> 2 65
> 3 31
> 3 61
> 3 71
> 3 79
>
> etc.
>
> and sometimes the rows will have 'mirrored' similarities
> eg.
>
> 1 88
>
> and further down...
> 88 1
>
> In this case, is there any suggestions to remove the second pair (i.e. 88 1) because they are practically the same from node1->88 and node 88->1
>
> ^^ thank you lots ^^
> Natalie :)

Another way:
>>A=[1 88; 3 16; 88 1; 72 4];
>>unique(sort(A,2),'rows','first')

Subject: remove row if it is 'mirrored'

From: Natalie Sin Hwee

Date: 20 Jul, 2010 14:19:05

Message: 4 of 4

"Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <i249gg$983$1@fred.mathworks.com>...
> "Natalie Sin Hwee " <sin.ng09@imperial.ac.uk> wrote in message <i248bi$n9k$1@fred.mathworks.com>...
> > Dear Mathwork users,
> > I have a 6000x2 matrix:
> >
> > 1 88
> > 1 67
> > 2 31
> > 2 30
> > 2 88
> > 2 65
> > 3 31
> > 3 61
> > 3 71
> > 3 79
> >
> > etc.
> >
> > and sometimes the rows will have 'mirrored' similarities
> > eg.
> >
> > 1 88
> >
> > and further down...
> > 88 1
> >
> > In this case, is there any suggestions to remove the second pair (i.e. 88 1) because they are practically the same from node1->88 and node 88->1
> >
> > ^^ thank you lots ^^
> > Natalie :)
>
> Another way:
> >>A=[1 88; 3 16; 88 1; 72 4];
> >>unique(sort(A,2),'rows','first')


Hey Sean and Wayne!!

Thanks loads for the reply! they both work!! seems so easy looking at a short line of code and i was cracking my brains over it :( *sob*
but THANK you sooo much !!!!

Cheers,
Natalie

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us