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:
Finding Duplicate values

Subject: Finding Duplicate values

From: Shantharam

Date: 11 May, 2012 08:31:25

Message: 1 of 6

I have a matrix which also has duplicate elements. Now I want to know what are the duplicate values?

For Example a = [1 2 3 4 5 5 6 8 9 1 2 6 9 9 12]. In this 1,2 5,6,9 are repeated.

I want to get the final matrix as [1 2 5 6 9 ].

Plz help me with code

Subject: Finding Duplicate values

From: Nasser M. Abbasi

Date: 11 May, 2012 08:51:58

Message: 2 of 6

On 5/11/2012 3:31 AM, Shantharam wrote:
> I have a matrix which also has duplicate elements. Now I want to know what are the duplicate values?
>
> For Example a = [1 2 3 4 5 5 6 8 9 1 2 6 9 9 12]. In this 1,2 5,6,9 are repeated.
>
> I want to get the final matrix as [1 2 5 6 9 ].
>
> Plz help me with code

just a hack, may be not efficient:

---------------------------------------
EDU>> a = [1 2 3 4 5 5 6 8 9 1 2 6 9 9 12];
EDU>> I = histc(a,a(1):a(end));
EDU>> find(I>1)
---------------------------------------

      1 2 5 6 9

--Nasser

Subject: Finding Duplicate values

From: Nasser M. Abbasi

Date: 11 May, 2012 08:54:00

Message: 3 of 6

On 5/11/2012 3:51 AM, Nasser M. Abbasi wrote:
> On 5/11/2012 3:31 AM, Shantharam wrote:
>> I have a matrix which also has duplicate elements. Now I want to know what are the duplicate values?
>>
>> For Example a = [1 2 3 4 5 5 6 8 9 1 2 6 9 9 12]. In this 1,2 5,6,9 are repeated.
>>
>> I want to get the final matrix as [1 2 5 6 9 ].
>>
>> Plz help me with code
>
> just a hack, may be not efficient:
>
> ---------------------------------------
> EDU>> a = [1 2 3 4 5 5 6 8 9 1 2 6 9 9 12];
> EDU>> I = histc(a,a(1):a(end));
> EDU>> find(I>1)
> ---------------------------------------
>
> 1 2 5 6 9
>


opps, sorry. meant this for general case:

EDU>> I=histc(a,min(a):max(a));
EDU>> find(I>1)

--Nasser

Subject: Finding Duplicate values

From: Shantharam

Date: 11 May, 2012 09:03:22

Message: 4 of 6

"Nasser M. Abbasi" <nma@12000.org> wrote in message <joik3e$qe6$2@speranza.aioe.org>...
> On 5/11/2012 3:51 AM, Nasser M. Abbasi wrote:
> > On 5/11/2012 3:31 AM, Shantharam wrote:
> >> I have a matrix which also has duplicate elements. Now I want to know what are the duplicate values?
> >>
> >> For Example a = [1 2 3 4 5 5 6 8 9 1 2 6 9 9 12]. In this 1,2 5,6,9 are repeated.
> >>
> >> I want to get the final matrix as [1 2 5 6 9 ].
> >>
> >> Plz help me with code
> >
> > just a hack, may be not efficient:
> >
> > ---------------------------------------
> > EDU>> a = [1 2 3 4 5 5 6 8 9 1 2 6 9 9 12];
> > EDU>> I = histc(a,a(1):a(end));
> > EDU>> find(I>1)
> > ---------------------------------------
> >
> > 1 2 5 6 9
> >
>
>
> opps, sorry. meant this for general case:
>
> EDU>> I=histc(a,min(a):max(a));
> EDU>> find(I>1)
>
> --Nasser




Thanks Nasser . Thank You Very much

- Shantharam

Subject: Finding Duplicate values

From: Nasser M. Abbasi

Date: 11 May, 2012 09:07:46

Message: 5 of 6

On 5/11/2012 3:54 AM, Nasser M. Abbasi wrote:
> On 5/11/2012 3:51 AM, Nasser M. Abbasi wrote:
>> On 5/11/2012 3:31 AM, Shantharam wrote:
>>> I have a matrix which also has duplicate elements. Now I want to know what are the duplicate values?
>>>
>>> For Example a = [1 2 3 4 5 5 6 8 9 1 2 6 9 9 12]. In this 1,2 5,6,9 are repeated.
>>>
>>> I want to get the final matrix as [1 2 5 6 9 ].
>>>
>>> Plz help me with code
>>
>> just a hack, may be not efficient:
>>
>> ---------------------------------------
>> EDU>> a = [1 2 3 4 5 5 6 8 9 1 2 6 9 9 12];
>> EDU>> I = histc(a,a(1):a(end));
>> EDU>> find(I>1)
>> ---------------------------------------
>>
>> 1 2 5 6 9
>>
>
>
> opps, sorry. meant this for general case:
>
> EDU>> I=histc(a,min(a):max(a));
> EDU>> find(I>1)
>


here is another hack, kind'a brute force method:

-------------------------------------------
EDU>> lis=unique(a);
EDU>> f=arrayfun(@(i) length(find(a==lis(i))),1:length(lis),'UniformOutput',false);
EDU>> lis(cell2mat(f)>1)
------------------------------------

      1 2 5 6 9

I think there is a better way. may be using the set theory functions in matlab.

--Nasser

Subject: Finding Duplicate values

From: Bruno Luong

Date: 11 May, 2012 09:24:07

Message: 6 of 6

"Shantharam " <ksramrepome@gmail.com> wrote in message <joiios$ptr$1@newscl01ah.mathworks.com>...
> I have a matrix which also has duplicate elements. Now I want to know what are the duplicate values?
>
> For Example a = [1 2 3 4 5 5 6 8 9 1 2 6 9 9 12]. In this 1,2 5,6,9 are repeated.
>
> I want to get the final matrix as [1 2 5 6 9 ].
>
> Plz help me with code

a = [1000000 1 2 3 4 5 5 6 8 9 1 2 6 9 9 12 1000000 ]

[b, ~, c] = unique(a);
b(accumarray(c(:),1)>1)

% Bruno

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