Unique numbers in array
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Joseph Pauwels
le 23 Avr 2014
Réponse apportée : Image Analyst
le 24 Avr 2014
I was charged to try and write my own unique function , I was thinking of first sorting the array, and then writing a loop that went through each number from min(min) to max(max) but cant figure out once a repeated number is identified to skip it. Any thoughts?
0 commentaires
Réponse acceptée
Image Analyst
le 24 Avr 2014
That could work, but why use a for loop when there are so much more "MATLAB-ish" ways of doing it, like:
m = randi(4, 1, 11)
sortedm = sort(m)
diffs = [1, diff(sortedm)]
uniqueNumbers = sortedm(find(diffs))
0 commentaires
Plus de réponses (1)
Azzi Abdelmalek
le 23 Avr 2014
Modifié(e) : Azzi Abdelmalek
le 23 Avr 2014
out= unique(A)
Or
out=unique(A,'rows')
0 commentaires
Voir également
Catégories
En savoir plus sur Multidimensional Arrays 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!