Longest common subsequence string LCS
11 次查看(过去 30 天)
显示 更早的评论
[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
回答(1 个)
John D'Errico
2011-6-3
Of course, since this is almost surely homework, that is not really a viable option. commonsubstring is pretty fast though.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Standard File Formats 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!