dppathplot4strmatch.m

来自「一个关于数据聚类和模式识别的程序,在生物化学,化学中因该都可以用到.希望对大家有」· M 代码 · 共 55 行

M
55
字号
function dpPathPlot4strMatch(str1, str2, lcsPath, lcsTable, prevx, prevy)
% dpPathPlot4strMatch: Plot the path of dynamic programming for string match.
%	Usage: dpPathPlot4strMatch(str1, str2, lcsPath, lcsTable, prevx, prevy)
%
%	This is primarily used in lcs.m and editDistance.m.
%	To see the result, try "lcs" or "editDistance".

%	Roger Jang, 20081009

m = length(str1);
n = length(str2);
%[xx, yy] = meshgrid(1:m, 1:n);
%plot(xx(:), yy(:), '.');
plot(nan, nan); axis([0 m+1 0 n+1]); box on; axis image
set(gca, 'xtick', 1:m);
set(gca, 'ytick', 1:n);
set(gca, 'xticklabel', str1(:));
set(gca, 'yticklabel', str2(:));
xlabel(['String1 = ', str1]);
ylabel(['String2 = ', str2]);
% === Plot bounding boxes for LCS table element
for i = 1:m
	for j = 1:n
		line(i, j, 'marker', 'square', 'markersize', 15, 'color', 'g', 'linestyle', 'none');
	end
end
% === Plot prevPos
for i=1:m
	for j=1:n
		now=i+j*sqrt(-1);
		next=prevx(i,j)+prevy(i,j)*sqrt(-1);
		start=now+(next-now)*0.2;
		stop =now+(next-now)*0.5;
		if prevx(i,j)>0 & prevy(i,j)>0
			arrowPlot(start, stop, [0 0 1]);
		end
	end
end
% === Plot DP path
for i=1:size(lcsPath,1)-1
	line(lcsPath(i:i+1, 1), lcsPath(i:i+1, 2), 'color', 'm', 'linewidth', 2);
end
% === Circle matched elements
for i=1:size(lcsPath,1)
	if str1(lcsPath(i,1))==str2(lcsPath(i,2))
		line(lcsPath(i,1), lcsPath(i,2), 'marker', 'o', 'markersize', 15, 'color', 'r', 'linestyle', 'none', 'linewidth', 2);
	end
end
% === Plot LCS table element
for i = 1:m
	for j = 1:n
		text(i, j, int2str(lcsTable(i,j)), 'hori', 'center');
	end
end

⌨️ 快捷键说明

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