Not able to get count of each elements in array itself
Afficher commentaires plus anciens
I am having this array..x=[ 1 2 3 1 2]
Now I want to replace it with count of the corresponding elements..here x should get modified to x=[2 2 1 2 2]
By using hist(x, unique(x)) I am able to do it but it gives the count for unique elements. I want the result to have the number of elements.
please help!
Réponse acceptée
Plus de réponses (1)
madhan ravi
le 30 Juin 2020
[~, ~, c] = unique(x);
v = accumarray(c, 1);
Wanted = v(c)
1 commentaire
Scott Tehelson
le 30 Juin 2020
Catégories
En savoir plus sur Matrices and Arrays dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!