【发布时间】:2015-11-26 09:12:53
【问题描述】:
我试图在 Matlab 中使用颜色图制作时空图。在 x 轴上,我想要格式为“HH:mm”的时间。问题是绘图在不正确的 x 轴上可见,或者绘图消失了
numberOfCells = 50;
numberOfTimeSteps = 120;
for i = 1:numberOfCells
for j = 1:numberOfTimeSteps
temp(i,j) = rand*10;
end
end
% to use this function, the array temp needs to be an array of size[rows=numberOfcells, columns=numberOfTimesteps]
% make the startTime and endTime to the strings
startTimeString = '2013-03-21 08:00:00';
endTimeString = '2013-03-21 10:00:00';
formatOut = 'HH:MM';
% convert startTimeString and endTimeString into serial date number
startTimeNum = datenum(datestr(startTimeString,formatOut));
endTimeNum = datenum(datestr(endTimeString,formatOut));
xData = linspace(startTimeNum,endTimeNum,numberOfTimeSteps/30 + 1);
% load the colormap from mycmap.mat
figure(1)
imagesc(temp);
colormap;
colorbar;
ax = gca;
ax.XTick = xData;
datetick('x',formatOut,'keepticks')
【问题讨论】:
-
在没有外部依赖的情况下,实际提供完整的可复制和粘贴的代码可能会有所帮助。我没有
mycmap.mat,也不想猜测如何调用你的函数。也就是说,为什么你有handle(gca)?简单地说ax = gca;会更标准。 -
关于在Matlab2014a或更早版本中需要handle(gca),这就是为什么使用这个。学校电脑。
-
set(gca,'XTick',xData)? -
试图在底部添加这段代码,x轴仍然没有,只有颜色图。当我使用这个集合时我应该删除一些东西吗(gca,'XTick',xData)
-
我的第一条评论的重要部分是“请提供一些可复制和粘贴的代码”。如果没有这个,我认为你不会得到很多帮助。
set命令只是一个建议,您可能会或可能不想使用,而不是包含ax的两行。
标签: matlab matlab-figure