How do I sort a vector in matlab by absolute value?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With