function I=findallseq(x,n);
%FINDALLSEQ--finds all sequences of the same value repeated n times
%
%I=findallseq(x,n);
%
% For a vector x, returns the starting location of any sequences where the
% same value is repeated n times.
%
% Ex: x=[ 1 2 3 3 3 3], n=3
%    then I=[3 4]
%

m=length(x);
I=zeros(size(x));%preallocate I
k=0;
if(m>n)
    %if length(x)< n, then I is blank--no work needed
    d=diff(x);
    m=m-1;%m is now length of d
    for j=1:m-(n-2)
        s=sum(d(j+(0:n-2)));
        if(s==0);
            k=k+1;
            I(k)=j;
        end
    end
end
if(k>0)
    I=I(1:k);%trim extras
else
    I=[];
end