sort matrix by absolute value
27 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
How do I sort a matrix by absolute value and display its original value with +,- sign?
0 commentaires
Réponse acceptée
Plus de réponses (1)
Steven Lord
le 30 Mar 2021
Specify the 'ComparisonMethod' name-value pair argument.
rng default
A = randi([-10 10], 5, 5)
[values, locations] = sort(A(:), 'ComparisonMethod', 'abs');
[values.'; locations.']
2 commentaires
DGM
le 30 Mar 2021
Do you know about when that option was introduced? I'm guessing it was some time around 2018, but release notes are vague and I only know it's not in R2015b.
Voir également
Catégories
En savoir plus sur Shifting and Sorting Matrices 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!