sort matrix by absolute value
Show older comments
How do I sort a matrix by absolute value and display its original value with +,- sign?
Accepted Answer
More Answers (1)
Specify the 'ComparisonMethod' name-value pair argument.
rng default
A = randi([-10 10], 5, 5)
[values, locations] = sort(A(:), 'ComparisonMethod', 'abs');
[values.'; locations.']
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!