MATLAB: How to select values bigger than a certain value & at least 4

following numbersfollowing valuesselect following values

Hi there,
I need to find a way to make a matlab command for the following: I have an array with 2500×1 doubles. And I need to find the doubles that are at least 150 and when there are more than 4 values >150 next to each other.
For example [125 165 150 124 126 154 103 99 160 198 *140] should return [0 0 0 0 0 0 0 0 0 0 0] and [149 *156 158 159 168 *149 120 *150 160 140 125] should return [0 1 1 1 1 0 0 0 0 0 0]
I have the following: x = array > 150 & ????
I don't know how to do the at least 4 following values in a simple way, I can only think of an if loop…
Does anyone know if there is a command for that?
Thanks in advance!

Best Answer

locations = strfind([0, YourArray > 150], [0 1 1 1 1]);
x = zeros(size(YourArray));
x([locations locations+1 locations+2 locations+3]) = 1;
Note: I made the code match your sample output, which does not agree with the written requirement. Your sample output has a location where exactly 4 in a row are > 150, but your written requirement was for more than 4 in a row are > 150.