Longest common subsequence string LCS
11 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
[EDIT: 20110603 09:53 CDT - reformat - WDR]
can some one help correct this matlab code for the recursive Longest common subsequence string LCS, the error "Subscripted assignment dimension" when run the following code
the function rec read two string from files the call the temp to fill the LCS table recursivly
function rec()
%to read the two strings from files
%x1='xyxxzxyzxy';
%x2='zxzyyzxxyxxz';
fid1=fopen('file1.txt');
fid2=fopen('file2.txt');
chs1 = textscan(fid1, '%c');
chs2 = textscan(fid2, '%c');
fclose(fid1);
fclose(fid2);
global x1;
global x2;
x1 =char(chs1);
x2 =char(chs2);
%to read the two strings from files
%creat a global table then call temp func to fill in
lenx1= length(x1)+1;
lenx2= length(x2)+1;
global L;
L = zeros(lenx1,lenx2);
temp (lenx1,lenx2);
%disp (L);
end
function result = temp (m,n)
global x1;
global x2;
global L;
result = L;
if m==1 || n==1
result(m,n) = 0;
elseif x1(m-1) == x2(n-1)
disp(['if=' x1(m-1)]);
disp(['if=' x2(n-1)]);
result(m,n) = temp(m-1,n-1) + 1;
else
disp(['else=' x1(m-1)]);
disp(['else=' x2(n-1)]);
result= max(temp(m,n-1), temp(m-1,n));
end
%L(m,n) = result(m,n);
return
end
3 Kommentare
Antworten (1)
John D'Errico
am 3 Jun. 2011
Of course, since this is almost surely homework, that is not really a viable option. commonsubstring is pretty fast though.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Standard File Formats finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!