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:
matrix and pdf

Subject: matrix and pdf

From: Konst

Date: 21 Feb, 2011 15:13:06

Message: 1 of 6

I have a one-column matrix with zeros and ones. I want a way to count how many zeros and how many ones there are and then plot a probability density function like these: In the x-axis I should have the wto values 0 and 1 and in the y-axis their frequency (how many 1 and 0). That is, I'll only have two points in the graph but I need to plot a 'wave' over these two points and not just a line that will just join them.
Any thoughts??

Subject: matrix and pdf

From: someone

Date: 21 Feb, 2011 15:54:06

Message: 2 of 6

"Konst " <konstance1@hotmail.com> wrote in message <ijtve1$stn$1@fred.mathworks.com>...
> I have a one-column matrix with zeros and ones. I want a way to count how many zeros and how many ones there are and then plot a probability density function like these: In the x-axis I should have the wto values 0 and 1 and in the y-axis their frequency (how many 1 and 0). That is, I'll only have two points in the graph but I need to plot a 'wave' over these two points and not just a line that will just join them.
> Any thoughts??

% if a is your one-column matrix with zeros and ones, then
sum(a) % is the number of ones
length(a) - sum(a) % is the number of zeros

% To plot, take a look at;

doc hist

Subject: matrix and pdf

From: Konst

Date: 21 Feb, 2011 17:10:21

Message: 3 of 6

"someone" wrote in message <iju1qu$t5l$1@fred.mathworks.com>...
> "Konst " <konstance1@hotmail.com> wrote in message <ijtve1$stn$1@fred.mathworks.com>...
> > I have a one-column matrix with zeros and ones. I want a way to count how many zeros and how many ones there are and then plot a probability density function like these: In the x-axis I should have the wto values 0 and 1 and in the y-axis their frequency (how many 1 and 0). That is, I'll only have two points in the graph but I need to plot a 'wave' over these two points and not just a line that will just join them.
> > Any thoughts??
>
> % if a is your one-column matrix with zeros and ones, then
> sum(a) % is the number of ones
> length(a) - sum(a) % is the number of zeros
>
> % To plot, take a look at;
>
> doc hist


I tried to work with the hist command but it just plots two dots (the two points).I tried scatter,PDF...and still nothing..Thanks though for your help!

Subject: matrix and pdf

From: someone

Date: 21 Feb, 2011 18:43:05

Message: 4 of 6

"Konst " <konstance1@hotmail.com> wrote in message <iju69t$5nq$1@fred.mathworks.com>...
> "someone" wrote in message <iju1qu$t5l$1@fred.mathworks.com>...
> > "Konst " <konstance1@hotmail.com> wrote in message <ijtve1$stn$1@fred.mathworks.com>...
> > > I have a one-column matrix with zeros and ones. I want a way to count how many zeros and how many ones there are and then plot a probability density function like these: In the x-axis I should have the wto values 0 and 1 and in the y-axis their frequency (how many 1 and 0). That is, I'll only have two points in the graph but I need to plot a 'wave' over these two points and not just a line that will just join them.
> > > Any thoughts??
> >
> > % if a is your one-column matrix with zeros and ones, then
> > sum(a) % is the number of ones
> > length(a) - sum(a) % is the number of zeros
> >
> > % To plot, take a look at;
> >
> > doc hist
>
>
> I tried to work with the hist command but it just plots two dots (the two points).I tried scatter,PDF...and still nothing..Thanks though for your help!

What EXACTLY is it that you want to plot?
What do you mean by "wave"?

Subject: matrix and pdf

From: Konst

Date: 21 Feb, 2011 20:06:04

Message: 5 of 6

"someone" wrote in message <ijubnp$bg8$1@fred.mathworks.com>...
> "Konst " <konstance1@hotmail.com> wrote in message <iju69t$5nq$1@fred.mathworks.com>...
> > "someone" wrote in message <iju1qu$t5l$1@fred.mathworks.com>...
> > > "Konst " <konstance1@hotmail.com> wrote in message <ijtve1$stn$1@fred.mathworks.com>...
> > > > I have a one-column matrix with zeros and ones. I want a way to count how many zeros and how many ones there are and then plot a probability density function like these: In the x-axis I should have the wto values 0 and 1 and in the y-axis their frequency (how many 1 and 0). That is, I'll only have two points in the graph but I need to plot a 'wave' over these two points and not just a line that will just join them.
> > > > Any thoughts??
> > >
> > > % if a is your one-column matrix with zeros and ones, then
> > > sum(a) % is the number of ones
> > > length(a) - sum(a) % is the number of zeros
> > >
> > > % To plot, take a look at;
> > >
> > > doc hist
> >
> >
> > I tried to work with the hist command but it just plots two dots (the two points).I tried scatter,PDF...and still nothing..Thanks though for your help!
>
> What EXACTLY is it that you want to plot?
> What do you mean by "wave"?

I want the distribution of these two. By 'wave' I mean something like the cosine but only in the +plane. But I only have these to points. Frequencies in the y-axis and 0 , 1 in the x. It must be a curve with two peaks in these two points.

Subject: matrix and pdf

From: ImageAnalyst

Date: 21 Feb, 2011 20:22:31

Message: 6 of 6

Konst:
Of course this is confusing, not only to someone but to everyone
except you. The PDF is simply the histogram like he said and so you
have only two bins - two bars. The first one is how many 0's there
are and the second one is a count of how many 1's there are. We think
this is what you asked for. What kind of a wave can you have when you
have only two bars? I have no idea what you mean by frequencies. You
can take the FFT of your input array - is that what you mean???? Or
maybe you want to fit some kind of function, like a Gaussian, to the
histogram curve. I have no idea. Please post a diagram showing what
you want.

By chance, by "density" you don't mean like some kind of running count
of how many 1's are inside some window that runs along your array?
Like an array like
[ 0 0 1 0 1 0 0 0 0 1 1 1 0 1 1 1 1]
would be more "dense" near the end of that array than near the
beginning of that array.
If so, you can use conv() to count the number of 1's in a sliding
window.
ImageAnalyst

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