I had a hard time trying to word this question properly; I apologize...
So I have a (very) big list of 0's and 1's:
AllTimes = {{0}, {0}, {0}, {1}, {1}, ...}
I want to somehow measure the number of continuous 1's (i.e., if the list is {{0}, {1}, {1}, {0}, {1}, {0}} I want to get the values 2 and 1). Is there a way of running a LengthWhile as a loop to give me not just one, but all lengths of continuous 1's?
I've also (miserably) failed to program a different method:
For[i = 1, i <= 100000, i++, t = 0
If[AllTimes[[{i}]] = 1,
t = t + 1]
If[AllTimes[[{i}]] = 0, Print[t], t = 0]]
I wanted each index of AllTimes to be read, and if it's 1, a value of t is added. If the value of an index gives 0, I want the t to be printed and reset back to 0. (I'm totally new to Mathematica programming... so please be gentle...). Although instead of printing, is there a way to also store the value of t before it is reseted to 0?
Thank you for taking your time to read my question...
Length /@ SequenceCases[l, {{1} ..}]? – Yves Klett Dec 03 '15 at 10:24Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign!
– Dec 03 '15 at 10:59