【发布时间】:2012-08-10 19:27:25
【问题描述】:
colormap 在matlab 中的作用域如何?下面的示例似乎表明它不是词法范围的,因为在代码块中设置的值可以在该块之外访问。
% example 1
for i=1:3
colormap('gray');
subplot(2,2,i);
imagesc(eye(5));
end
subplot(2,2,4);
imagesc(eye(5));
此外,它的定义似乎取决于是否调用了其他函数(例如,figure)。在以下两个示例中,colormap 似乎是根据是否调用其他函数来动态限定范围的。
% example 2
colormap(gray);
for i=1:4
subplot(2,2,i);
imagesc(eye(5));
end
% example 3
colormap(gray);
figure;
for i=1:4
subplot(2,2,i);
imagesc(eye(5));
end
在“示例 2”中,灰色映射应用于每个 image。在“示例 3”中,每个 image 使用默认的 colormap (jet),这表明调用函数 figure 会取代之前的 colormap 定义,将它们重置为默认值。还有哪些函数调用有这个属性?
最后,调用colormap('default')有什么效果?鉴于我之前假设调用figure 将colormap 重置为默认值,下面的代码不会像我预期的那样生成带有graycolormap 的图像。相反,所有数字都使用jetcolormap。在什么意义上 gray colormap 被设为默认值?
% example 4
colormap(gray);
colormap('default');
figure;
for i=1:4
subplot(2,2,i);
imagesc(eye(5));
end
【问题讨论】:
标签: matlab plot matlab-figure color-mapping