You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

DEL 1

a)

function res = isPalindrome ( str )
n = size (str , 2);
res = true ;
for i =1: n
    if str (i) ~= str (n+1-i)
        res = false ;
        break
    end
end
end

b)

function res = sequenceFinder (sequence,start,stop )
len = 0;
index = 0;
for i = 1:length(sequence)-length(stop)
    if (length(start) <= length(sequence(i:end))) && strcmp(start,sequence(i:i+length(start)-1))
        indexS = i;
    elseif (length(stop) <= length(sequence(i:end))) && strcmp(stop,sequence(i:i+length(start)-1))
        indexE = i;
        if len < indexE -indexS
            len = indexE -indexS;
            index = indexS;
        end
    end  
end
res = sequence(index:index+len+length(stop)-1);
end

Eventuelt kan den lages litt enklere ved hjelp av matlabs strfind() funksjon.

DEL 2

a)

 

  • No labels