Path: news.mathworks.com!not-for-mail From: <HIDDEN> Newsgroups: comp.soft-sys.matlab Subject: Re: Sort complex numbers according to their signs... Date: Sun, 11 Mar 2012 20:10:12 +0000 (UTC) Organization: The MathWorks, Inc. Lines: 54 Message-ID: <jjj0r4$js$1@newscl01ah.mathworks.com> References: <jjii2k$ht1$1@newscl01ah.mathworks.com> Reply-To: <HIDDEN> NNTP-Posting-Host: www-05-blr.mathworks.com Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: newscl01ah.mathworks.com 1331496612 636 172.30.248.37 (11 Mar 2012 20:10:12 GMT) X-Complaints-To: news@mathworks.com NNTP-Posting-Date: Sun, 11 Mar 2012 20:10:12 +0000 (UTC) X-Newsreader: MATLAB Central Newsreader 1187260 Xref: news.mathworks.com comp.soft-sys.matlab:760615 "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