Matlab中的RECLOR imagesc Inf值

Matlab中的RECLOR imagesc Inf值,matlab,infinity,Matlab,Infinity,我正在使用imagesc显示矩阵中的数据。矩阵包含NaNs和Inf值。我能回忆起我们的NaNs背景色。我正在使用jet Color map,我想将我们的Inf值恢复为黑色或其他非背景色或jet配色方案上的颜色。默认情况下,Matlab颜色Inf值与最大值相同。下面是一个简单的示例代码,让您了解我的意思 a = [1 2 NaN; 4 Inf 6; 7 5 3]; %// Matrix of data test_image= imagesc(a); %// Creates imagesc

我正在使用
imagesc
显示矩阵中的数据。矩阵包含
NaNs
Inf
值。我能回忆起我们的
NaNs
背景色。我正在使用jet Color map,我想将我们的
Inf
值恢复为黑色或其他非背景色或jet配色方案上的颜色。默认情况下,Matlab颜色
Inf
值与最大值相同。下面是一个简单的示例代码,让您了解我的意思

 a = [1 2 NaN; 4 Inf 6; 7 5 3];
%// Matrix of data
    test_image= imagesc(a);
%// Creates imagesc figure.
    colormap('jet');
%// Uses jet color scheme.
    set(test_image,'alphadata',~isnan(a))
%// Ignores NaN values and sets NaN values to background colour.
    colorbar
%// Adds a colorbar

在这个例子中,我希望中间的单元格(2,2)是黑色的。与左下角最大值7(3,1)的颜色不同。

最简单的方法是定义自己的颜色贴图:

cm = [jet(255) ; 0 0 0];
colormap(cm);

imagesc(a);
caxis([min(a(:)) max(a(:))+1]);

最好的,

我在Matlab central运行的特定Matlab论坛上发布了这个问题。人们并不总是回答这个论坛。我得到的答案并不十分有效,但使我走上了正确的道路。我得出了以下结论:

a = [1 2 NaN; 4 Inf 6; 7 5 3];
% sample data
infRGB = reshape([0 0 0],1,1,3);   
%set to RGB triple for desired color for inf values in this case black
%denoted by [0 0 0].
infimgdata = repmat(infRGB, size(a,1), size(a,2)); 
%same size as "a" but all the one color
infimg = image(infimgdata, 'alphadata', ~isnan(a));  
%plots an image based on 'infimgdata' excludes NaN's therefore making NaN
%values white
hold on
%plot to same figure
test_image = imagesc(a,'alphadata', ~(isnan(a)|isinf(a)));
%plot data
colormap(jet());
colorbar
hold off
% stop plotting to the same figure