![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/183861/image.png)
Count numbers of identical rows
36 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Panayiotis Christodoulou
le 4 Mai 2016
Commenté : Star Strider
le 4 Mai 2016
Hi there,
I am a new member here.
I have a sample dataset:
3 5
3 5
5 6
5 6
5 6
5 7
6 8
I want the measure how many times does an identical row appears.
so the final result should be :
3 5 2
3 5 2
5 6 3
5 6 3
5 6 3
5 7 1
6 8 1
I have done it with a for loop but because my dataset is 8million x 2 if taking a lot of time and I am looking for an alternative solution.
Thanks
1 commentaire
Star Strider
le 4 Mai 2016
Panayiotis Christodoulou’s ‘Answer’ moved here:
there was an error on how the data were represented
please see atatched image
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/183861/image.png)
Réponse acceptée
Star Strider
le 4 Mai 2016
This works:
M = [3 5
3 5
5 6
5 6
5 6
5 7
6 8];
[Mu,ia,ic] = unique(M, 'rows', 'stable'); % Unique Values By Row, Retaining Original Order
h = accumarray(ic, 1); % Count Occurrences
maph = h(ic); % Map Occurrences To ‘ic’ Values
Result = [M, maph]
Result =
3 5 2
3 5 2
5 6 3
5 6 3
5 6 3
5 7 1
6 8 1
2 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!