2014-07-08 99 views

回答

6

只需使用一个颜色表三行。每行按R,G,B分量定义颜色。

A = randi(100,16,16); %// example data 
imagesc(A) %// display matrix as image 
colormap([1 0 0; 0 1 0; 0 0 1]) %// apply colormap 
colorbar %// show color bar 

enter image description here

这定义颜色之间均匀间隔的阈值。如果你需要更多的控制,你需要有超过三行,并重复一些颜色。例如,

colormap([1 0 0; 1 0 0; 0 1 0; 0 0 1]) %// apply colormap 

将定义第一颜色的50%阈值,第二颜色的75%和第三颜色的100%。

0

按照这个例子:How to create a custom colormap programmatically?但不是R = linspace(0,t(1),50)'你会使用R = ones(50,1)*t(1)

或更简单:

如果颜色1为t1 = [r1, g1, b1]等则

map(1:34, :) = repmat(t1, 33, 1) 
map(35:68, :) = repmat(t2, (67-34), 1) 

等等

map(1:34, :) = bsxfun(@times, t, ones(33,3)) 等等

0

检查我的答案here

您可以使用这些代码,并决定价值与否,它只是2的代码行之间进行插补。

结果图像显示在GYR cutom色彩映射的原始文章中。

enter image description here

2

借此例如:

% some matrix with integer values in the range [0,100] 
Z = peaks; 
Z(:) = round((Z(:)-min(Z(:))) ./ range(Z(:))*100); 

% show as image (with scaled color mapping) 
image(Z, 'CDataMapping','scaled') 
caxis([0 100]) % set axes CLim property 
colormap(eye(3)) % set figure Colormap property 
colorbar   % show colorbar 

注意,颜色被缩放到范围[0 100],该范围被映射到当前的人物的颜色表(我们设置为仅三种颜色)。

peaks