MATLAB: How to obtain the value of a vector when a condition is met for multiple times in a row

multiple conditions

Hello,
How can I get the position of averror when the condition of <10^-4 is met 4 times in a row for the first time?
The code below shows the problem. In other words I want to obtain the value of e when the next 3 value of e are also meeting the condition above.
[e]=find(averror<(10^-4))
for k=1:size(e)
if e(k)==e(k+1)-1 && e(k)==e(k+2)-2 && e(k)==e(k+3)-3
m=e(k);
end
end
Does anybody know this?

Best Answer

e = averror < (10^-4);
m = strfind([false e(:).'], [0 1 1 1 1]);
m(1)