Sort complex vectors in specific order

434 views Asked by At

I have vector with eigenvalues:

e = 

-0.4094 + 3.9387i
-0.4094 - 3.9387i
-0.0156 + 0.5645i
-0.0156 - 0.5645i

And I would like to sort this vector like that:

e_sort =

-0.0156 + 0.5645i
-0.4094 + 3.9387i
-0.0156 - 0.5645i
-0.4094 - 3.9387i

The rule is: First must be:

 -a+b*i

and then:

 -a-b*i

We can say, that:

  0 < b_1 < b_2 < ... < b_n

Thanks,

1

There are 1 answers

0
Rash On BEST ANSWER
e1 = e(imag(e) >= 0);
e2 = e(imag(e) < 0);
newe = cat(1,sort(e1),sort(e2))

newe =

-0.0156 + 0.5645i
-0.4094 + 3.9387i
-0.0156 - 0.5645i
-0.4094 - 3.9387i