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:
Removing Duplicate Entries

Subject: Removing Duplicate Entries

From: ratnesh

Date: 26 Aug, 2009 08:14:04

Message: 1 of 6

Hi all.

i have
a=[1 2 5
     2 6 7
     1 2 9
     1 3 6
     5 1 2 % to be remove this is shifted code of 1 2 5
     3 6 7
     7 2 6] % to be remove ,this is shifted code of 2 6 7

How can I remove the duplicate entries.thier column may can be change?

expected result
a=
     1 2 5
     2 6 7
     1 2 9
     1 3 6
     3 6 7
Thank you.

Subject: Removing Duplicate Entries

From: Jos

Date: 26 Aug, 2009 08:35:19

Message: 2 of 6

"ratnesh " <iam_ratnesh@yahoo.co.in> wrote in message <h72qsc$m0n$1@fred.mathworks.com>...
> Hi all.
>
> i have
> a=[1 2 5
> 2 6 7
> 1 2 9
> 1 3 6
> 5 1 2 % to be remove this is shifted code of 1 2 5
> 3 6 7
> 7 2 6] % to be remove ,this is shifted code of 2 6 7
>
> How can I remove the duplicate entries.thier column may can be change?
>
> expected result
> a=
> 1 2 5
> 2 6 7
> 1 2 9
> 1 3 6
> 3 6 7
> Thank you.

In your definition of duplicates two rows are the same if the elements are the same when you SORT them. So look for UNIQUE sorted rows, as in

[result_sorted,INX] = unique(sort(a,2),'rows')
expected_result = a(INX,:)

hth
Jos

Subject: Removing Duplicate Entries

From: us

Date: 26 Aug, 2009 08:35:20

Message: 3 of 6

"ratnesh " <iam_ratnesh@yahoo.co.in> wrote in message <h72qsc$m0n$1@fred.mathworks.com>...
> Hi all.
>
> i have
> a=[1 2 5
> 2 6 7
> 1 2 9
> 1 3 6
> 5 1 2 % to be remove this is shifted code of 1 2 5
> 3 6 7
> 7 2 6] % to be remove ,this is shifted code of 2 6 7
>
> How can I remove the duplicate entries.thier column may can be change?
>
> expected result
> a=
> 1 2 5
> 2 6 7
> 1 2 9
> 1 3 6
> 3 6 7
> Thank you.

one of the solutions

     m=[
          1 2 5
          2 6 7
          1 2 9
          1 3 6
          5 1 2
          3 6 7
          7 2 6
     ];
     r=unique(sort(m,2),'rows')
%{
% r =
          1 2 5
          1 2 9
          1 3 6
          2 6 7
          3 6 7
%}

us

Subject: Removing Duplicate Entries

From: ratnesh

Date: 26 Aug, 2009 09:51:04

Message: 4 of 6

hi,
thanks for answering me ..here is the problem again that is ,when if there is increase in matrix's column say a(:,4), a(:,5), a(:,6).....a(:,7).then solution as given by you ,a matrix not sorting shifted and repeated versions of previously occured rows.
thanks

  
"Jos " <#10584@fileexchange.com> wrote in message <h72s47$13i$1@fred.mathworks.com>...
> "ratnesh " <iam_ratnesh@yahoo.co.in> wrote in message <h72qsc$m0n$1@fred.mathworks.com>...
> > Hi all.
> >
> > i have
> > a=[1 2 5
> > 2 6 7
> > 1 2 9
> > 1 3 6
> > 5 1 2 % to be remove this is shifted code of 1 2 5
> > 3 6 7
> > 7 2 6] % to be remove ,this is shifted code of 2 6 7
> >
> > How can I remove the duplicate entries.thier column may can be change?
> >
> > expected result
> > a=
> > 1 2 5
> > 2 6 7
> > 1 2 9
> > 1 3 6
> > 3 6 7
> > Thank you.
>
> In your definition of duplicates two rows are the same if the elements are the same when you SORT them. So look for UNIQUE sorted rows, as in
>
> [result_sorted,INX] = unique(sort(a,2),'rows')
> expected_result = a(INX,:)
>
> hth
> Jos

Subject: Removing Duplicate Entries

From: Avni Pllana

Date: 26 Aug, 2009 11:06:32

Message: 5 of 6

> hi,
> thanks for answering me ..here is the problem again
> that is ,when if there is increase in matrix's column
> say a(:,4), a(:,5), a(:,6).....a(:,7).then solution
> as given by you ,a matrix not sorting shifted and
> repeated versions of previously occured rows.
> thanks
>

Hi Ratnesh,

I posted a solution to your problem at:

http://mathforum.org/kb/message.jspa?messageID=6825873&tstart=15

Best regards,
    Avni

Subject: Removing Duplicate Entries

From: Jos

Date: 26 Aug, 2009 11:10:22

Message: 6 of 6

"ratnesh " <iam_ratnesh@yahoo.co.in> wrote in message <h730i8$9i9$1@fred.mathworks.com>...
> hi,
> thanks for answering me ..here is the problem again that is ,when if there is increase in matrix's column say a(:,4), a(:,5), a(:,6).....a(:,7).then solution as given by you ,a matrix not sorting shifted and repeated versions of previously occured rows.
> thanks

Sorry, but this doesn't make sense to me. Can you rephrase your question and give an example?

Jos

Tags for 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