I want to count unique elements of a cell array in Matlab. How can I do this? Thank you.

```
c = {'a', 'b', 'c', 'a'};
% count unique elements, return the following struct
unique_count.a = 2
unique_count.b = 1
unique_count.c = 1
```

Skip to content
# Matlab – how to count unique elements of a cell in matlab

###### Related Question

matlab

I want to count unique elements of a cell array in Matlab. How can I do this? Thank you.

```
c = {'a', 'b', 'c', 'a'};
% count unique elements, return the following struct
unique_count.a = 2
unique_count.b = 1
unique_count.c = 1
```

## Best Solution

To count unique elements, you can combine UNIQUE with ACCUMARRAY

To produce the structure, use NUM2CELL and STRUCT: