MATLAB: Display 4 consecutive numbers in array

consecutive indicies

I have the Array a= 9 10 11 12 17 18 19 20 23 24 How can i get the code to display when the 4 indices are consecutive and when they appear. example: 9 10 11 12 and 17 18 19 20

Best Answer

Strangely enough, strfind also find patterns in numeric arrays:
a = [9 10 11 12 17 18 19 20 23 24];
indices = strfind(diff(a), [1 1 1])
See also Loren's blog on the subject of finding patterns for alternative algorithms.