% How many times does the pattern GATTC appear?

dna= 'AGTCGATTCACACGGTACGTAACTTTACGGATTCCCCCATTTACGAGATTCTCCAAATGC';
str= 'GATTC';

n= 0;  % number of occurences of str
for k= 1:length(dna)-length(str)+1
    checkSum= sum(dna(k:k+length(str)-1)==str);
    if checkSum==length(str)
        n= n+1;
    end
end

fprintf('Pattern %s occurs %d time.\n', str, n)
    