MATLAB: Finding Consecutive values in array that meet specific Criteria

arrayconsecutivedataImage Processing Toolboxstorethresholdvalidvaluevector

I have a list of values
a = [3 10 7 6 2 3 4 8]
I want to find the longest list of terms where a is greater than a certain threshold. So when a>5. These values would be [10 7 6] for the specific example and I would also like this be the output. Each value is consecutive and greater than the threshold. Although 8 is greater than the threshold, it is not consecutive. I would like to be able to do this without a looping structure if at all possible.

Best Answer

S=regionprops(a>5,'PIxelIdxList','Area');
[~,idx]=max([S.Area]);
longest = a(S(idx).PixelIdxList)