From: us on 27 Jul 2010 09:59 "CNN " <cnln2000(a)yahoo.co.uk> wrote in message <i2mo54$ghl$1(a)fred.mathworks.com>... > > > us <us(a)neurol.unizh.ch> wrote in message <c1d25ce5-d43a-4eab-a954-eda4ff332543(a)w30g2000vbs.googlegroups.com>... > > On Jul 27, 2:57 pm, "CNN " <cnln2...(a)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...(a)neurol.unizh.ch> wrote in message <i2mj54$h4...(a)fred.mathworks.com>... > > > > "CNN " <cnln2...(a)yahoo.co.uk> wrote in message <i2mio0$ko...(a)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
From: Walter Roberson on 27 Jul 2010 10: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)
From: CNN on 27 Jul 2010 10:12 > > > > '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
From: us on 27 Jul 2010 10:17 On Jul 27, 4:12 pm, "CNN " <cnln2...(a)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
From: Andy on 27 Jul 2010 10:19 > 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?
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 Prev: Connecting Agilent PSA & PSG to MatLab Next: mxarray pointer |