Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Sort complex numbers according to their signs...

Subject: Sort complex numbers according to their signs...

From: Florent Kadrija

Date: 11 Mar, 2012 15:58:12

Message: 1 of 3

Hi,

as I am new to matlab so I need your help. I want so sort, let say this vector of complex symbols according to their signs: for instance consider:
a=0.4681 + 0.3268i
  -0.6969 - 0.6949i
  -0.6662 - 0.6710i
   0.6428 + 0.6534i
  -0.5679 - 0.6836i
   0.6971 + 0.7041i
   0.5564 - 0.6839i
   0.5863 + 0.6813i
  -0.5791 - 0.6611i
  -0.3268 + 0.6967i
  -0.6055 + 0.6077i
   0.6975 - 0.5981i
   0.6832 + 0.5515i
  -0.5244 - 0.7060i
  -0.7041 - 0.5799i
   0.6681 + 0.7046i
  -0.6560 - 0.6955i
   0.6029 + 0.5291i

there are 4 possibilities:
1. a=b+jc
2. a=b-jc
3. a=-b+jc
4. a=-b-jc

What I want is to sort all the complex symbols from vector a in the above given order. Can any body help me doing this???

Ann after sorting in the given order the next step is to mapp these symbols in the given order, for instance:

 1 0 2 0 1 2 0 3 3 1 1

which means that all complex number are mapped according to:

1. a=b+jc ---> 0
2. a=b-jc ---> 1
3. a=-b+jc --->2
4. a=-b-jc--> 3

Is this possible to do, and can anybody give me an Idea or help me how to do this...

Thanks in advance,
Flori

Subject: Sort complex numbers according to their signs...

From: Roger Stafford

Date: 11 Mar, 2012 20:10:12

Message: 2 of 3

"Florent Kadrija" <florent.kadrija@gmail.com> wrote in message <jjii2k$ht1$1@newscl01ah.mathworks.com>...
> Hi,
>
> as I am new to matlab so I need your help. I want so sort, let say this vector of complex symbols according to their signs: for instance consider:
> a=0.4681 + 0.3268i
> -0.6969 - 0.6949i
> -0.6662 - 0.6710i
> 0.6428 + 0.6534i
> -0.5679 - 0.6836i
> 0.6971 + 0.7041i
> 0.5564 - 0.6839i
> 0.5863 + 0.6813i
> -0.5791 - 0.6611i
> -0.3268 + 0.6967i
> -0.6055 + 0.6077i
> 0.6975 - 0.5981i
> 0.6832 + 0.5515i
> -0.5244 - 0.7060i
> -0.7041 - 0.5799i
> 0.6681 + 0.7046i
> -0.6560 - 0.6955i
> 0.6029 + 0.5291i
>
> there are 4 possibilities:
> 1. a=b+jc
> 2. a=b-jc
> 3. a=-b+jc
> 4. a=-b-jc
>
> What I want is to sort all the complex symbols from vector a in the above given order. Can any body help me doing this???
>
> Ann after sorting in the given order the next step is to mapp these symbols in the given order, for instance:
>
> 1 0 2 0 1 2 0 3 3 1 1
>
> which means that all complex number are mapped according to:
>
> 1. a=b+jc ---> 0
> 2. a=b-jc ---> 1
> 3. a=-b+jc --->2
> 4. a=-b-jc--> 3
>
> Is this possible to do, and can anybody give me an Idea or help me how to do this...
>
> Thanks in advance,
> Flori
- - - - - - - - -
 mapp = (imag(a)<0) + 2*(real(a)<0);
 [~,p] = sort(mapp);
 a_sorted = a(p);

  Note: I have assumed here that you want no sorting other than by the signs in the real and imaginary parts. Also I assume that when either of these parts is zero, the corresponding sign is plus.

Roger Stafford

Subject: Sort complex numbers according to their signs...

From: Florent Kadrija

Date: 11 Mar, 2012 20:26:13

Message: 3 of 3

"Roger Stafford" wrote in message <jjj0r4$js$1@newscl01ah.mathworks.com>...
> "Florent Kadrija" <florent.kadrija@gmail.com> wrote in message <jjii2k$ht1$1@newscl01ah.mathworks.com>...
> > Hi,
> >
> > as I am new to matlab so I need your help. I want so sort, let say this vector of complex symbols according to their signs: for instance consider:
> > a=0.4681 + 0.3268i
> > -0.6969 - 0.6949i
> > -0.6662 - 0.6710i
> > 0.6428 + 0.6534i
> > -0.5679 - 0.6836i
> > 0.6971 + 0.7041i
> > 0.5564 - 0.6839i
> > 0.5863 + 0.6813i
> > -0.5791 - 0.6611i
> > -0.3268 + 0.6967i
> > -0.6055 + 0.6077i
> > 0.6975 - 0.5981i
> > 0.6832 + 0.5515i
> > -0.5244 - 0.7060i
> > -0.7041 - 0.5799i
> > 0.6681 + 0.7046i
> > -0.6560 - 0.6955i
> > 0.6029 + 0.5291i
> >
> > there are 4 possibilities:
> > 1. a=b+jc
> > 2. a=b-jc
> > 3. a=-b+jc
> > 4. a=-b-jc
> >
> > What I want is to sort all the complex symbols from vector a in the above given order. Can any body help me doing this???
> >
> > Ann after sorting in the given order the next step is to mapp these symbols in the given order, for instance:
> >
> > 1 0 2 0 1 2 0 3 3 1 1
> >
> > which means that all complex number are mapped according to:
> >
> > 1. a=b+jc ---> 0
> > 2. a=b-jc ---> 1
> > 3. a=-b+jc --->2
> > 4. a=-b-jc--> 3
> >
> > Is this possible to do, and can anybody give me an Idea or help me how to do this...
> >
> > Thanks in advance,
> > Flori
> - - - - - - - - -
> mapp = (imag(a)<0) + 2*(real(a)<0);
> [~,p] = sort(mapp);
> a_sorted = a(p);
>
> Note: I have assumed here that you want no sorting other than by the signs in the real and imaginary parts. Also I assume that when either of these parts is zero, the corresponding sign is plus.
>
> Roger Stafford


Thanks a lot for your advice.

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us