10

我正在尝试模拟此图: 在此处输入图像描述

如果我有一个相关矩阵,我该如何创建这样的输出?

4

3 回答 3

8

如果您有一个n x n相关矩阵M和一个包含每个 bin 的标签L的长度向量n,则可以使用如下内容:

imagesc(M); % plot the matrix
set(gca, 'XTick', 1:n); % center x-axis ticks on bins
set(gca, 'YTick', 1:n); % center y-axis ticks on bins
set(gca, 'XTickLabel', L); % set x-axis labels
set(gca, 'YTickLabel', L); % set y-axis labels
title('Your Title Here', 'FontSize', 14); % set title
colormap('jet'); % set the colorscheme
colorbar on; % enable colorbar

旋转 x 轴标签并非易事,但 MATLAB Central File Exchange 包含一些解决方案

于 2012-04-30T20:16:35.630 回答
3

Adding to @Thomas C. G.'s answer, I'd use:

imagesc(myMatrix);
colormap(jet);
colorbar;

% then to set the axis titles you'll have to use
% Please note the curly braces for the cell array
labelNames = {'USA','NASDAQ','Dow Jones'};
set(gca,'XTickLabel',labelNames);   % gca gets the current axis
set(gca,'YTickLabel'labelNames);   % gca gets the current axis

Unfortunately, AFAIK, making the text labels vertical as they are in your figure is a bit harder. Maybe somebody else has knowledge to the contrary.

于 2012-04-30T20:04:26.597 回答
1

要将矩阵绘制为图像,您只需调用两个函数:

image(myMatrix)
colormap(jet)

colormap函数定义用于渲染图像的颜色模式。您发布的图像使用“jet”颜色图。

并使用颜色栏功能在图像旁边显示色阶。

于 2012-04-30T19:14:32.737 回答