sort matrix by absolute value
27 次查看(过去 30 天)
显示 更早的评论
采纳的回答
更多回答(1 个)
Steven Lord
2021-3-30
Specify the 'ComparisonMethod' name-value pair argument.
rng default
A = randi([-10 10], 5, 5)
[values, locations] = sort(A(:), 'ComparisonMethod', 'abs');
[values.'; locations.']
2 个评论
DGM
2021-3-30
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Shifting and Sorting Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!