Thread Subject: REMOVE DUPLICATE ENTRIES WITHOUT SORTING

Subject: REMOVE DUPLICATE ENTRIES WITHOUT SORTING

From: GAURAV

Date: 10 Nov, 2010 06:47:03

Message: 1 of 8

Hi!

I needed a method to remove duplicate entries from a matrix but without hurting the original order of the matrix. I used unique but it returned in the sorted form. I want it to be returned in the original just removing any duplicate entries coming after the first one.

Please help me out.

Regards,
Gaurav.

Subject: REMOVE DUPLICATE ENTRIES WITHOUT SORTING

From: Darren Rowland

Date: 10 Nov, 2010 06:55:05

Message: 2 of 8

Hi Gaurav,

This blog post may help you.
http://blogs.mathworks.com/loren/2009/11/26/unique-values-without-rearrangement/

Hth,
Darren

Subject: REMOVE DUPLICATE ENTRIES WITHOUT SORTING

From: Mehmet OZTURK

Date: 10 Nov, 2010 07:41:03

Message: 3 of 8

i tihnk you need this code :)
http://www.mathworks.com/matlabcentral/fileexchange/15242-myunique

Subject: REMOVE DUPLICATE ENTRIES WITHOUT SORTING

From: GAURAV

Date: 10 Nov, 2010 08:03:05

Message: 4 of 8

Hi Darren!

Thanks a lot! That helped! :)
Appreciate it! :)

Regards,
Gaurav

"Darren Rowland" <darrenjremovethisrowland@hotmail.com> wrote in message <ibdfk9$m62$1@fred.mathworks.com>...
> Hi Gaurav,
>
> This blog post may help you.
> http://blogs.mathworks.com/loren/2009/11/26/unique-values-without-rearrangement/
>
> Hth,
> Darren

Subject: REMOVE DUPLICATE ENTRIES WITHOUT SORTING

From: Bruno Luong

Date: 10 Nov, 2010 08:04:04

Message: 5 of 8

"GAURAV " <gsharda@engineering.uiowa.edu> wrote in message <ibdf57$mni$1@fred.mathworks.com>...
> Hi!
>
> I needed a method to remove duplicate entries from a matrix but without hurting the original order of the matrix. I used unique but it returned in the sorted form. I want it to be returned in the original just removing any duplicate entries coming after the first one.
>

 [~, I]=unique(A,'first')
A(sort(I))

Bruno

Subject: REMOVE DUPLICATE ENTRIES WITHOUT SORTING

From: GAURAV

Date: 10 Nov, 2010 08:04:04

Message: 6 of 8

Hi Mehmet!

Thanks a lot! :) Appreciate your reply!

Regards,
Gaurav
"Mehmet OZTURK" <mehmetozturk@mathworks.com> wrote in message <ibdiaf$bsg$1@fred.mathworks.com>...
> i tihnk you need this code :)
> http://www.mathworks.com/matlabcentral/fileexchange/15242-myunique

Subject: REMOVE DUPLICATE ENTRIES WITHOUT SORTING

From: GAURAV

Date: 10 Nov, 2010 08:33:03

Message: 7 of 8

Hi Bruno!

Thanks a lot for your reply. Appreciate it! :)

Regards,
Gaurav
"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <ibdjlk$p0k$1@fred.mathworks.com>...
> "GAURAV " <gsharda@engineering.uiowa.edu> wrote in message <ibdf57$mni$1@fred.mathworks.com>...
> > Hi!
> >
> > I needed a method to remove duplicate entries from a matrix but without hurting the original order of the matrix. I used unique but it returned in the sorted form. I want it to be returned in the original just removing any duplicate entries coming after the first one.
> >
>
> [~, I]=unique(A,'first')
> A(sort(I))
>
> Bruno

Subject: REMOVE DUPLICATE ENTRIES WITHOUT SORTING

From: Bruno Luong

Date: 10 Nov, 2010 10:36:04

Message: 8 of 8

I wrote:
> >
> > [~, I]=unique(A,'first')
> > A(sort(I))

It is probably better using logical indexing and avoid a second sort (unique is a first sort):

A=ceil(10*rand(1,15));

[~, I]=unique(A,'first')
selected(I)=true; % selected must not exist
A(selected)

Bruno

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

rssFeed for this Thread

Contact us at files@mathworks.com