The Math Forum

Search All of the Math Forum:

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

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

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

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: 123
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


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
elseif test(k)==0


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

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.