Path: news.mathworks.com!not-for-mail
From: "Sadik " <sadik.hava@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: counting dots
Date: Mon, 19 Jan 2009 03:28:02 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 41
Message-ID: <gl0s02$or2$1@fred.mathworks.com>
References: <gkug9i$2b4$1@fred.mathworks.com> <gkuiim$t29$1@fred.mathworks.com> <gl0qse$8jn$1@fred.mathworks.com>
Reply-To: "Sadik " <sadik.hava@gmail.com>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1232335682 25442 172.30.248.35 (19 Jan 2009 03:28:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 19 Jan 2009 03:28:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1666517
Xref: news.mathworks.com comp.soft-sys.matlab:512377


"Freda " <fredawerdiger@hotmail.com> wrote in message <gl0qse$8jn$1@fred.mathworks.com>...
> "Sadik " <sadik.hava@gmail.com> wrote in message <gkuiim$t29$1@fred.mathworks.com>...
> > "Freda " <fredawerdiger@hotmail.com> wrote in message <gkug9i$2b4$1@fred.mathworks.com>...
> > > Take this plot of complex numbers:
> > > 
> > > one=rand(128);
> > > two=rand(128).*pi;
> > > comp=one.*exp(i.*two);
> > > re=real(comp);
> > > im=imag(comp);
> > > plot(re,im,'k.','MarkerSize',4)
> > > 
> > > How do i find out the number of dots in a given section?
> > > ie, counting dots.
> > 
> > Hello Freda,
> > 
> > You can easily filter the vector comp with respect to the given section so as to give the number of points in that section. But the section should clearly be defined.
> > 
> > As an example, if the section will be "Those points whose magnitudes are less than 0.5", you can even filter the vector one rather than comp. So the number of points in that section would be: length(sum(one<0.5)).
> > 
> > Hope this helps.
> 
> 
> Hi,
> i don't really understand. Does this count the number of points in a section of the plot? How, if your using the original vector? Bc the real part of the complex function isn't the same as the vector 'one'. also, why the sum(one<0.5)???
> 
> thanks,
> Freda.

As a matter of fact, the code I have given does not count the number of points in a given section. It does count the number of points if the section is the set of points whose magnitudes are less than 0.5 . The vector "one" does not keep the real parts, as you have mentioned. It keeps the magnitudes of the complex points. I gave that example to show you how to handle a situation in general. You could also do that by sum(abs(comp)<0.5). Another example would be the section of points whose real parts are positive. Then, the number of points in that section would be: [I am sorry, there should not have been length() in the example I gave in the previous post.]

sum(real(comp)>0)

or, with your variables,

sum(re>0)

Coming to your last question: sum(re>0) for example works the following way. (re>0) is a vector of logical 1s and 0s. If, for instance, re = [-2 4 0 1]'; then (re>0) would return [0 1 0 1]'; because -2<0, 4>0 and so on.

When we apply sum() to this result, it counts the number of logical true values. So, for re as given above, sum(re>0) would return 2, which is correctly the number of points whose real parts are positive.