MATLAB: How to find consecutive values above a certain threshold

consecutive values

Hi.
I'm picking out values from a hourly data set, and I want to pick out values that are above 12 at least three consecutive times. Any tips on how I can do this?
example: A=[0 1 2 5 7 8 13 17 28 11 6 0 2 1 4]
I want to put the three values 13 17 28 into a vector.
Help is greatly appreciated!
– Kristine

Best Answer

A=[0 1 2 5 7 8 13 17 28 11 6 0 2 1 40 55 88 47 4 44 ]
idx=A>12;
ii1=strfind([0 idx 0],[0 1]);
ii2=strfind([0 idx 0],[1 0])-1;
ii=(ii2-ii1+1)>=3;
out=arrayfun(@(x,y) A(x:y),ii1(ii),ii2(ii),'un',0);
celldisp(out)