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

New to MATLAB?

Finding Duplicate Values per Column

Asked by RDG

RDG

on 22 Oct 2011
Latest activity Edited by Clemens

Clemens

on 19 Mar 2014
Accepted Answer by Jan Simon

Jan Simon

Greetings, suppose Column A has these values - 7 18 27 42 65 49 54 65 78 82 87 98

Is there a way to compare the values (row by row) and search for duplicates? (I'm using Matlab R2010b)I don't want the duplicated values to be removed.

Thanks.

0 Comments

RDG

RDG

Tags

Products

No products are associated with this question.

3 Answers

Answer by Jan Simon

Jan Simon

on 22 Oct 2011
Accepted answer
A = [7 18 27 42 65 49 54 65 78 82 87 98];
[n, bin] = histc(A, unique(A));
multiple = find(n > 1);
index    = find(ismember(bin, multiple));

Now the values A(index) appear mutliple times.

1 Comment

Teik Yee

Teik Yee

on 19 Nov 2012

thx

Jan Simon

Jan Simon

Answer by the cyclist

the cyclist

on 22 Oct 2011

Here's a slightly different way:

X = [1 2 3 4 5 5 5 1];
uniqueX = unique(X);
countOfX = hist(X,uniqueX);
indexToRepeatedValue = (countOfX~=1);
repeatedValues = uniqueX(indexToRepeatedValue)
numberOfAppearancesOfRepeatedValues = countOfX(indexToRepeatedValue)

3 Comments

Harold

Harold

on 13 Apr 2012

Is there a way that I can use this approach for a cell array. Suppose I have a 1x4 cell array and each cell contains a (x,y) co-ordinates. Can I somehow modify your solution to search for duplicate cells and get rid of them?

Yowh

Yowh

on 19 Nov 2012

Harold can you give an example of your cell array variable ?

Jan Simon

Jan Simon

on 19 Nov 2012

@Yowh: It is unlikely, that Harold listens to comments after 8 months.

the cyclist

the cyclist

Answer by Hannes Greim

Hannes Greim

on 19 Jan 2013

you can use "tabulate" for cell arrays.

1 Comment

Clemens

Clemens

on 19 Mar 2014

Working only for versions after 2012 with the intro of tables.

Hannes Greim

Hannes Greim

Contact us