Here is a simple solution to detect the first occurence of values repeated 3 times; you could customize it to be more general.
clear all clc
A = [2 6 8 2 8 8 3 2 9 8 8 11 12 18 17 18 18 18 15 3];% Create a dummy vector
CheckSimilar = 0;
for i = 2:length(A)
if A(i) == A(i-1)
CheckSimilar = CheckSimilar +1;
end
if CheckSimilar == 3
fprintf('The value %i is repeated %i times',A(i),CheckSimilar);
return
end
end