2014-07-08 98 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