lcs_demo.m

来自「patten regnization source从1-14章能运行」· M 代码 · 共 39 行

M
39
字号
str1 = 'GAATTCAGTTA';
str2 = 'GGATCGA';
m = length(str1);
n = length(str2);
figure;
%[xx, yy] = meshgrid(1:m, 1:n);
%plot(xx(:), yy(:), '.');
axis([0 m+1 0 n+1]);
box on;
set(gca, 'xtick', 1:m);
set(gca, 'ytick', 1:n);
set(gca, 'xticklabel', char(double(str1)'));
set(gca, 'yticklabel', char(double(str2)'));

% LCS  矫累
[count, lcs_path, lcs_str, lcstable] = lcs(str1, str2);
xlabel(['String1 = ', str1]);
ylabel(['String2 = ', str2]);
title(['LCS table and LCS path; with LCS = ', lcs_str]);

% LCS 抛捞喉 敲吩
for i = 1:m,
	for j = 1:n,
		text(i, j, int2str(lcstable(i,j)), 'hori', 'center');
	end
end

% LCS 菩胶 敲吩
for i = 1:size(lcs_path,1)-1,
	line(lcs_path(i:i+1, 1), lcs_path(i:i+1, 2));
end

% 概莫等 夸家俊 悼弊扼固 弊府扁
temp = lcstable((lcs_path(:,2)-1)*m+lcs_path(:,1)); % 菩胶甫 蝶扼 LCS 墨款泼
temp = [0; temp];
index = find(diff(temp));
match_point = lcs_path(index, :);
line(match_point(:,1), match_point(:, 2), ...
	'marker', 'o', 'markersize', 15, 'color', 'r', 'linestyle', 'none');

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?