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”中,每个 都使用默认值colormap( jet) image,这表明调用该函数会figure取代以前的colormap定义,将它们重置为默认值。还有哪些其他函数调用具有此属性?
最后,调用的效果是colormap('default')什么?鉴于我之前的假设,即调用将figure重置colormap为默认值,以下代码不会像我预期的那样生成带有gray colormap. 相反,所有数字都使用jet colormap. 在什么意义上已经gray colormap被默认了?
% example 4
colormap(gray);
colormap('default');
figure;
for i=1:4
subplot(2,2,i);
imagesc(eye(5));
end