Reputation: 485
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
Upvotes: 3
Views: 2911
Reputation: 3193
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
Upvotes: 8