matplot.m

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

M
84
字号
function matPlot(a, matrixName, gridColor, fontSize, fontColor, rowLabel, colLabel);
% matPlot: Display a matrix in a figure window.
%	Usage: matPlot(a, matrixName, gridColor, fontSize, fontColor, rowLabel, colLabel);
%
%	For example:
%		matPlot(magic(10));
%
%	Roger Jang, 20071009

if nargin<1, selfdemo; return; end
if nargin<2, matrixName=''; end
if nargin<3, gridColor='k'; end
if nargin<4, fontSize=10; end
if nargin<5, fontColor='b'; end
if nargin<6,
	for i=1:size(a, 1)
		rowLabel{i}=int2str(i);
	end
end
if nargin<7,
	for i=1:size(a, 2)
		colLabel{i}=int2str(i);
	end
end

% Clear the current axis
cla reset;
[m,n]=size(a);

% Place the text in the correct locations
% Index over number of rows
for rowCnt=1:m,
	% Index over number of columns
	for colCnt=1:n,
		numberString=num2str(a(rowCnt,colCnt));
		text(colCnt-.5,m-rowCnt+.5,numberString, ...
			'HorizontalAlignment','center', ...
			'Color','b', ...
			'FontWeight','bold', ...
			'FontSize',fontSize);
	end;
end;

for rowCnt=1:m,
	text(-0.1, m-rowCnt+.5, rowLabel{rowCnt}, ...
		'HorizontalAlignment','right', ...
		'Color','r', ...
		'FontWeight','bold', ...
		'FontSize',fontSize);
end;

for colCnt=1:n,
	text(colCnt-.5, m+.1, colLabel{colCnt}, ...
		'HorizontalAlignment','left', ...
		'rot', 90, ...
		'Color','r', ...
		'FontWeight','bold', ...
		'FontSize',fontSize);
end;



set(gca,'Box','on', ...
        'Visible','on', ...
        'xLim',[0 n], ...
        'xGrid','on', ...
        'xTickLabel',[], ...
        'xTick',0:n, ...
        'yGrid','on', ...
        'yLim',[0 m], ...
        'yTickLabel',[], ...
        'yTick',0:m, ...
        'DataAspectRatio',[1, 1, 1], ... 
        'GridLineStyle',':', ...
        'LineWidth',3, ...
        'XColor',gridColor, ...
        'YColor',gridColor);

xlabel(matrixName);

% ====== Self demo
function selfdemo
mat=magic(11);
feval(mfilename, mat, 'Magic Matrix');

⌨️ 快捷键说明

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