Can I use UNIQUE to get a count of the number of times each element is repeated?
Show older comments
I would like to know if the UNIQUE function has the capability of returning the number of times each element appears in an array.
Accepted Answer
More Answers (1)
Lola Davidson
on 6 Sep 2022
10 votes
>> a = [12 34 78 8 12 3 34 34]';
>> [counts, groupnames] = groupcounts(a)
counts =
1
1
2
3
1
groupnames =
3
8
12
34
78
Categories
Find more on Shifting and Sorting Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!