
counting events
Posted:
Aug 22, 2013 3:45 PM


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(k1)+test2(k); elseif test(k)==0 test3(k)=0 end end test3=test3.';
Thanks

