MATLAB: Finding consecutive NaN in matrix

matrix

i have a vector like [1,2,3,4,NaN,NaN,NaN,7,8,9]. I want to find if there is 3 consecutive NaN present in the vector. i can go for loop but is there more direct and easy way to do that.

Best Answer

>> x = [1,2,3,4,NaN,NaN,NaN,7,8,9] ;
>> strfind( isnan(x), true(1,3) )
ans =
5
if you just need a "flag found", do it as follows:
>> found = ~isempty(strfind( isnan(x), true(1,3) ))
found =
logical
1