## Finding Duplicate Values per Column

### RDG (view profile)

on 22 Oct 2011
Latest activity Edited by Clemens

on 19 Mar 2014

### Jan Simon (view profile)

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.

## Products

No products are associated with this question.

### Jan Simon (view profile)

on 22 Oct 2011
```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.

Teik Yee

on 19 Nov 2012

thx

### the cyclist (view profile)

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)
```

Harold

### Harold (view profile)

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 (view profile)

on 19 Nov 2012

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

Jan Simon

### Jan Simon (view profile)

on 19 Nov 2012

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

### Hannes Greim (view profile)

on 19 Jan 2013

you can use "tabulate" for cell arrays.

Clemens

### Clemens (view profile)

on 19 Mar 2014

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

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