MATLAB: How to extract the events which have more than 3 consecutive rows

sequence

Hi,
I have array of data as follows;
idx3=0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 2 1 0 0 1 0 1 1 1 1 2 2 1 1 1 0 0 1 2 2 2 1 0 0 1 1 2 2 2 1 2 2 0 1 1 2 2 2 0 2
I want to find number of events which "2" comes for more or equal 3 consecutive rows. In my data set there are 3 events which show "2" in more than 3 (row # 83-85, 91-93 and 10-102).
How can i find it in matlab?
Thanks

Best Answer

r=3; how many repeats
mask = idx3.' == 2; %row
starts = strfind([false mask], [0 ones(1,r)];
stops = strfind([mask, false], [ones(1,r) 0]) + r-1;