I would appreciate if someone showed me an easy way to do this. Let's say I have a vector in MATLAB like
d = [3 2 4 2 2 2 3 5 1 1 2 1 2 2 2 2 2 9 2]
I want to find the series of consecutive number "twos" and the lengths of those series.
Number twos can easily be found by x=find(d==2)
. But what I want is to get a vector which contains the lengths of all series of consecutive number twos, which means that my result in this case would be a vector like this:
[1 3 1 5 1].
Anyone who could help me?