sort matrix by absolute value
27 views (last 30 days)
Show older comments
How do I sort a matrix by absolute value and display its original value with +,- sign?
0 Comments
Accepted Answer
More Answers (1)
Steven Lord
on 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 Comments
DGM
on 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.
See Also
Categories
Find more on Shifting and Sorting Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!