sort matrix by absolute value
27 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
How do I sort a matrix by absolute value and display its original value with +,- sign?
0 Commenti
Risposta accettata
Più risposte (1)
Steven Lord
il 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 Commenti
DGM
il 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.
Vedere anche
Categorie
Scopri di più su Shifting and Sorting Matrices in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!