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:
counting dots

Subject: counting dots

From: Freda

Date: 18 Jan, 2009 05:56:02

Message: 1 of 4

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.

Subject: counting dots

From: Sadik

Date: 18 Jan, 2009 06:35:02

Message: 2 of 4

"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.

Subject: counting dots

From: Freda

Date: 19 Jan, 2009 03:09:02

Message: 3 of 4

"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.

Subject: counting dots

From: Sadik

Date: 19 Jan, 2009 03:28:02

Message: 4 of 4

"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.

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