MATLAB: Function to find longest string of consecutive ones

MATLAB

hi all, i'm new here. i'v got some difficulties to draft a function to find longest string of consecutive ones (DNA sequence)
for ex: AAAGGTCCATTTTTTTAA
it shows TTTTTTT

Best Answer

This is quick made example how it may work. Nbest tells number of letters in the longest string and Lbest tells what letters the string consists of
clear;clc;close all;
str='AAATTTTTCCCCCAATTCCC';
AGTCstr='AGTC';
Strsize=size(str);
AGTCsize=size(AGTCstr);
temp=0;
k=0;
Nbest=0;
for i=1:Strsize(2)
for j=1:AGTCsize(2)
h=strcmp(str(i),AGTCstr(j));
if h==0
continue
end
if h==1
k=k+1;
if strcmp(temp,str(i))==0
if k>=Nbest
Nbest=k;
Lbest=temp;
end
k=0;
end
temp=str(i);
end
end
end