Reputation: 141
How do I sort a vector in matlab by absolute value?
Upvotes: 5
Views: 6127
Reputation: 74940
Use the second output of SORT to get the order, then sort the initial array:
a = [-2 1 3 -1.1]; [~,idx] = sort(abs(a)); result = a(idx) result = 1 -1.1 -2 3
Upvotes: 9