Sorting by imaginary part in MatLab
complex-numbers, matlab, sorting
Solution
Please try something like this:
a = [1 + 1i; 1 - 1i; 1 - 2*1i];
[sorted, idx] = sort(imag(a));
a = a(idx);
a =
1.0000 - 2.0000i
1.0000 - 1.0000i
1.0000 + 1.0000i
Problem
So I have a vector that contains complex values. I want to sort them in order of ascending imaginary order. Is there a way to do this? Accorsing to the sort documentation, `sort` will sort via magnitude. Thanks