How to sort a struct
140 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Peter Meier
le 23 Juil 2020
Commenté : Stephen23
le 23 Juil 2020
Is it possible to sort a struct? I want to sort the third column.
0 should be in the first row and the highest value at the end (last row). The other values are not important and should be the same ranking.
Thank you.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/335841/image.png)
2 commentaires
Réponse acceptée
Mohammad Sami
le 23 Juil 2020
Modifié(e) : Mohammad Sami
le 23 Juil 2020
You can try like this.
% a = somestruct;
[~,index] = sortrows([a.Var3].');
a = a(index);
2 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Structures 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!