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:
Counting the number of data points in a plot

Subject: Counting the number of data points in a plot

From: CNN

Date: 27 Jul, 2010 12:17:05

Message: 1 of 11

Good day,
I'm plotting a series of graphs from data in a .dat file containing thousands of data, some positive, some negative in value. I want to put an label/annotation indicating the percentage of points that are positive and negative.
Any suggestion will be helpful.

Subject: Counting the number of data points in a plot

From: us

Date: 27 Jul, 2010 12:24:04

Message: 2 of 11

"CNN " <cnln2000@yahoo.co.uk> wrote in message <i2mio0$kou$1@fred.mathworks.com>...
> Good day,
> I'm plotting a series of graphs from data in a .dat file containing thousands of data, some positive, some negative in value. I want to put an label/annotation indicating the percentage of points that are positive and negative.
> Any suggestion will be helpful.

a hint:

     help sum;
     help text;
     help legend;

us

Subject: Counting the number of data points in a plot

From: CNN

Date: 27 Jul, 2010 12:57:04

Message: 3 of 11

'sum' will add the values of the data. I need to know the number of data that are positive and the number that are negative. And I can't use legend because I can only have one legend and I'll need 4 notations. I was planning to use the function 'text' as soon as I figure it out.

"us " <us@neurol.unizh.ch> wrote in message <i2mj54$h4d$1@fred.mathworks.com>...
> "CNN " <cnln2000@yahoo.co.uk> wrote in message <i2mio0$kou$1@fred.mathworks.com>...
> > Good day,
> > I'm plotting a series of graphs from data in a .dat file containing thousands of data, some positive, some negative in value. I want to put an label/annotation indicating the percentage of points that are positive and negative.
> > Any suggestion will be helpful.
>
> a hint:
>
> help sum;
> help text;
> help legend;
>
> us

Subject: Counting the number of data points in a plot

From: us

Date: 27 Jul, 2010 13:01:07

Message: 4 of 11

On Jul 27, 2:57 pm, "CNN " <cnln2...@yahoo.co.uk> wrote:
> 'sum' will add the values of the data. I need to know the number of data that are positive and the number that are negative. And I can't use legend because I can only have one legend and I'll need 4 notations. I was planning to use the function 'text' as soon as I figure it out.
>
>
>
> "us " <u...@neurol.unizh.ch> wrote in message <i2mj54$h4...@fred.mathworks.com>...
> > "CNN " <cnln2...@yahoo.co.uk> wrote in message <i2mio0$ko...@fred.mathworks.com>...
> > > Good day,
> > > I'm plotting a series of graphs from data in a .dat file containing thousands of data, some positive, some negative in value. I want to put an label/annotation indicating the percentage of points that are positive and negative.
> > > Any suggestion will be helpful.
>
> > a hint:
>
> >      help sum;
> >      help text;
> >      help legend;
>
> > us- Hide quoted text -
>
> - Show quoted text -

well... SUM works perfectly well...

one of the solutions
- a hint: use logical indexing...

     v=-3:5;
     sneg=sum(v<0)
% sneg = 3
     spos=sum(v>0)
% spos=5

us

Subject: Counting the number of data points in a plot

From: CNN

Date: 27 Jul, 2010 13:49:24

Message: 5 of 11



us <us@neurol.unizh.ch> wrote in message <c1d25ce5-d43a-4eab-a954-eda4ff332543@w30g2000vbs.googlegroups.com>...
> On Jul 27, 2:57 pm, "CNN " <cnln2...@yahoo.co.uk> wrote:
> > 'sum' will add the values of the data. I need to know the number of data that are positive and the number that are negative. And I can't use legend because I can only have one legend and I'll need 4 notations. I was planning to use the function 'text' as soon as I figure it out.
> >
> >
> >
> > "us " <u...@neurol.unizh.ch> wrote in message <i2mj54$h4...@fred.mathworks.com>...
> > > "CNN " <cnln2...@yahoo.co.uk> wrote in message <i2mio0$ko...@fred.mathworks.com>...
> > > > Good day,
> > > > I'm plotting a series of graphs from data in a .dat file containing thousands of data, some positive, some negative in value. I want to put an label/annotation indicating the percentage of points that are positive and negative.
> > > > Any suggestion will be helpful.
> >
> > > a hint:
> >
> > >      help sum;
> > >      help text;
> > >      help legend;
> >
> > > us- Hide quoted text -
> >
> > - Show quoted text -
>
> well... SUM works perfectly well...
>
> one of the solutions
> - a hint: use logical indexing...
>
> v=-3:5;
> sneg=sum(v<0)
> % sneg = 3
> spos=sum(v>0)
> % spos=5
>
> us

Ok I'm kind of surprised. I thought sum adds up the values of data in a matrix/array or am I mistaken? And I'm fairly new to MATLAB so I have no idea how to go about the logical indexing. I though about using the function 'size' but how to make it check the data for positive or negative values, that I've not figured it out yet.
Would posting my code help?

Subject: Counting the number of data points in a plot

From: us

Date: 27 Jul, 2010 13:59:07

Message: 6 of 11

"CNN " <cnln2000@yahoo.co.uk> wrote in message <i2mo54$ghl$1@fred.mathworks.com>...
>
>
> us <us@neurol.unizh.ch> wrote in message <c1d25ce5-d43a-4eab-a954-eda4ff332543@w30g2000vbs.googlegroups.com>...
> > On Jul 27, 2:57 pm, "CNN " <cnln2...@yahoo.co.uk> wrote:
> > > 'sum' will add the values of the data. I need to know the number of data that are positive and the number that are negative. And I can't use legend because I can only have one legend and I'll need 4 notations. I was planning to use the function 'text' as soon as I figure it out.
> > >
> > >
> > >
> > > "us " <u...@neurol.unizh.ch> wrote in message <i2mj54$h4...@fred.mathworks.com>...
> > > > "CNN " <cnln2...@yahoo.co.uk> wrote in message <i2mio0$ko...@fred.mathworks.com>...
> > > > > Good day,
> > > > > I'm plotting a series of graphs from data in a .dat file containing thousands of data, some positive, some negative in value. I want to put an label/annotation indicating the percentage of points that are positive and negative.
> > > > > Any suggestion will be helpful.
> > >
> > > > a hint:
> > >
> > > >      help sum;
> > > >      help text;
> > > >      help legend;
> > >
> > > > us- Hide quoted text -
> > >
> > > - Show quoted text -
> >
> > well... SUM works perfectly well...
> >
> > one of the solutions
> > - a hint: use logical indexing...
> >
> > v=-3:5;
> > sneg=sum(v<0)
> > % sneg = 3
> > spos=sum(v>0)
> > % spos=5
> >
> > us
>
> Ok I'm kind of surprised. I thought sum adds up the values of data in a matrix/array or am I mistaken? And I'm fairly new to MATLAB so I have no idea how to go about the logical indexing. I though about using the function 'size' but how to make it check the data for positive or negative values, that I've not figured it out yet.
> Would posting my code help?

well... isn't the example helpful enough(?)...
let's dissect it

     v=-3:5
% v = -3 -2 -1 0 1 2 3 4 5
% now
     ix=v<0
% ix = 1 1 1 0 0 0 0 0 0 % <- a LOGICAL array...
% and
     sum(ix)
% ans = 3

us

Subject: Counting the number of data points in a plot

From: Walter Roberson

Date: 27 Jul, 2010 14:11:20

Message: 7 of 11

CNN wrote:

> Ok I'm kind of surprised. I thought sum adds up the values of data in a
> matrix/array or am I mistaken?

It does.

v < 0

results in an array of true and false values, and

sum(v < 0)

adds up those true's (numeric 1) and false's (numeric 0)

Subject: Counting the number of data points in a plot

From: CNN

Date: 27 Jul, 2010 14:12:49

Message: 8 of 11


> > > > 'sum' will add the values of the data. I need to know the number of data that are positive and the number that are negative. And I can't use legend because I can only have one legend and I'll need 4 notations. I was planning to use the function 'text' as soon as I figure it out.

> > > > > > I'm plotting a series of graphs from data in a .dat file containing thousands of data, some positive, some negative in value. I want to put an label/annotation indicating the percentage of points that are positive and negative.
> > > > > > Any suggestion will be helpful.
> > > >
> > > > > a hint:
> > > >
> > > > >      help sum;
> > > > >      help text;
> > > > >      help legend;
> > > >
> > > > > us- Hide quoted text -
> > > >
> > > > - Show quoted text -
> > >
> > > well... SUM works perfectly well...
> > >
> > > one of the solutions
> > > - a hint: use logical indexing...
> > >
> > > v=-3:5;
> > > sneg=sum(v<0)
> > > % sneg = 3
> > > spos=sum(v>0)
> > > % spos=5
> > >
> > > us
> >
> > Ok I'm kind of surprised. I thought sum adds up the values of data in a matrix/array or am I mistaken? And I'm fairly new to MATLAB so I have no idea how to go about the logical indexing. I though about using the function 'size' but how to make it check the data for positive or negative values, that I've not figured it out yet.
> > Would posting my code help?
>
> well... isn't the example helpful enough(?)...
> let's dissect it
>
> v=-3:5
> % v = -3 -2 -1 0 1 2 3 4 5
> % now
> ix=v<0
> % ix = 1 1 1 0 0 0 0 0 0 % <- a LOGICAL array...
> % and
> sum(ix)
> % ans = 3
>
> us

Oh thank you so much. I think I'll be able to work with this. I'll try it now.
By the way, does sum give the number of data values that are 1 or does it add up all the 1s?
thanks once again

Subject: Counting the number of data points in a plot

From: us

Date: 27 Jul, 2010 14:17:11

Message: 9 of 11

On Jul 27, 4:12 pm, "CNN " <cnln2...@yahoo.co.uk> wrote:
> > > > > 'sum' will add the values of the data. I need to know the number of data that are positive and the number that are negative. And I can't use legend because I can only have one legend and I'll need 4 notations. I was planning to use the function 'text' as soon as I figure it out.
> > > > > > > I'm plotting a series of graphs from data in a .dat file containing thousands of data, some positive, some negative in value. I want to put an label/annotation indicating the percentage of points that are positive and negative.
> > > > > > > Any suggestion will be helpful.
>
> > > > > > a hint:
>
> > > > > >      help sum;
> > > > > >      help text;
> > > > > >      help legend;
>
> > > > > > us- Hide quoted text -
>
> > > > > - Show quoted text -
>
> > > > well... SUM works perfectly well...
>
> > > > one of the solutions
> > > > - a hint: use logical indexing...
>
> > > >      v=-3:5;
> > > >      sneg=sum(v<0)
> > > > %    sneg = 3
> > > >      spos=sum(v>0)
> > > > %    spos=5
>
> > > > us
>
> > > Ok I'm kind of surprised. I thought sum adds up the values of data in a matrix/array or am I mistaken? And I'm fairly new to MATLAB so I have no idea how to go about the logical indexing. I though about using the function 'size' but how to make it check the data for positive or negative values, that I've not figured it out yet.
> > > Would posting my code help?
>
> > well... isn't the example helpful enough(?)...
> > let's dissect it
>
> >      v=-3:5
> > %    v = -3    -2    -1     0     1     2     3     4     5
> > % now
> >      ix=v<0
> > %    ix = 1     1     1     0     0     0     0     0     0     % <- a LOGICAL array...
> > % and
> >      sum(ix)
> > %    ans = 3
>
> > us
>
> Oh thank you so much. I think I'll be able to work with this. I'll try it now.
> By the way, does sum give the number of data values that are 1 or does it add up all the 1s?
> thanks once again- Hide quoted text -
>
> - Show quoted text -

well... if you take the word SUM litterally: (i think) it ADDs them
up...

:-)
us

Subject: Counting the number of data points in a plot

From: Andy

Date: 27 Jul, 2010 14:19:25

Message: 10 of 11

> By the way, does sum give the number of data values that are 1 or does it add up all the 1s?

I suppose it adds them, but what's the difference?

Subject: Counting the number of data points in a plot

From: us

Date: 27 Jul, 2010 14:23:04

Message: 11 of 11

us
> well... if you take the word SUM litterally: (i think) it ADDs them

hmmmmm... better make this a LITERALLY...

:-)
us

Tags for 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