Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: counting events
Replies: 4   Last Post: Aug 22, 2013 6:15 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Jonathan Allan

Posts: 116
Registered: 12/7/04
counting events
Posted: Aug 22, 2013 3:45 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Hi,

I'm trying to figure out a way to perform a cumulative count of events. Here's my example. I have the following matrix:

test=[0,0,1,1,1,0,0,0,0,0,1,1,0 etc].'; and I am trying to get to the following solution: test2=[0,0,1,2,3,0,0,0,0,0,1,2,0 etc];

Basically, I would like to add those events characterized by a 1, so that the end result is the sum of all the 1s in the sequence.
I started with the following but its not working (I can see why but can't figure out how to get around it)...

for k = 1:length(test)
if test(k)>0
test3(k)=test(k-1)+test2(k);
elseif test(k)==0
test3(k)=0
end
end
test3=test3.';

Thanks



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.