How to find 'numbers' of unique variable in matrix. How many quantity of variables.
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Triveni
le 30 Oct 2015
Réponse apportée : Konstantinos Sofos
le 30 Oct 2015
x=[2 5 2 52 5 25 2 5 2 22 5 2 5 52 5 55 4 5 5 2 5 5 25 2 5 2 54 5 54 5 2 5 5 5 5 5 5 5 25 2 255 2 5 5 2 55 2 5 5 2 5 5 2 255 2 52 5 2 5 ];
unique(x)
ans =
Columns 1 through 6
2 4 5 22 25 52
Columns 7 through 9
54 55 255
How to find numbers using command. How many numbers of unique variable.
0 commentaires
Réponse acceptée
Konstantinos Sofos
le 30 Oct 2015
Hi,
To reformulate your question (as I understood it) you would like to be able to return the count of occurrences of each element in a vector. There are multiple ways to do this. One solution would be by using hist and unique functions
x=[2 5 2 52 5 25 2 5 2 22 5 2 5 52 5 55 4 5 5 2 5 5 25 2 5 2 54 5 54 5 2 5 5 5 5 5 5 5 25 2 255 2 5 5 2 55 2 5 5 2 5 5 2 255 2 52 5 2 5 ];
>> [a,b]=hist(x,unique(x))
a =
17 1 28 1 3 3 2 2 2
b =
2 4 5 22 25 52 54 55 255
where a(i) is the (count) of b(i).
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Get Started with Optimization Toolbox dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!