只想檢查是否可以用3種顏色製作自定義色彩圖? (不需要漸變)。Matlab只有3種顏色的自定義色彩圖
示例:從0-100
數據範圍,
- 所以
0-33
是一種顏色, 34-67
是另一種顏色,- 和
68-100
是另一種顏色。
只想檢查是否可以用3種顏色製作自定義色彩圖? (不需要漸變)。Matlab只有3種顏色的自定義色彩圖
示例:從0-100
數據範圍,
0-33
是一種顏色,34-67
是另一種顏色,68-100
是另一種顏色。只需使用一個顏色表三行。每行按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
這定義顏色之間均勻間隔的閾值。如果你需要更多的控制,你需要有超過三行,並重復一些顏色。例如,
colormap([1 0 0; 1 0 0; 0 1 0; 0 0 1]) %// apply colormap
將定義第一顏色的50%閾值,第二顏色的75%和第三顏色的100%。
按照這個例子: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))
等等
藉此例如:
% 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],該範圍被映射到當前的人物的顏色表(我們設置爲僅三種顏色)。