How to get all values existing in arrays/matrices?
Afficher commentaires plus anciens
Hello,
Let say I have a 3-by-2 array with random integer values. For example,
myArray = [98 56; 58 52; 100 56];
What I want to do is, I want to get all value in the array and its frequency and save it to another array like this,
listValue = [98 1; 56 2; 58 1; 52 1; 100 1];
Is there any function or a way to do it?
Thank you in advance.
1 commentaire
Arif Widianto
le 24 Mar 2020
Réponse acceptée
Plus de réponses (2)
Read about unique
a = myArray(:) ;
[cnt_unique, unique_a] = hist(a,unique(a)) ;
Walter Roberson
le 24 Mar 2020
1 vote
See unique() and accumarray. Or unique and histc or histcounts (but be careful about the last value in histcounts). Or use a loop. Or use sparse(). Lots of ways.
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!