How can I display all 'NaN' values as black in my image to differentiate them from lowest values?
조회 수: 2 (최근 30일)
이전 댓글 표시
MathWorks Support Team
2009년 6월 27일
편집: MathWorks Support Team
2021년 4월 19일
I am using imagesc to display matrices. Some of them are 'NaN' values, and I want those to be black in the display so that I can distinguish the 'NaN' values from the lowest values.
채택된 답변
MathWorks Support Team
2009년 6월 27일
This can be done by writing code that will check for the NaN values in the image matrix and set it black. For example, create a 5X5 matrix 'a' containing some NaN values and some '0' values. Get minimum and maximum values of that matrix and also location of all 'NaN' values. Then replace all NaN with values which are less than minimum number present in that matrix. Then redraw the colormap and plot the image.
a =[
0 0.8843 NaN 0.3900 NaN
NaN 0.5880 0.8256 0.1117 0.4950
0.8620 0.1548 NaN 0.1363 0.7476
NaN 0.8999 0.3185 0.6787 NaN
0.5144 0 0.5341 0.4952 0.8507
];
minv = min(min(a));
maxv = max(max(a));
a(isnan(a)) = minv-((maxv-minv)/5);
ddd=[0 0 0;jet(10)];
colormap(ddd);
imagesc(a)
댓글 수: 1
Nitin Khola
2016년 6월 13일
편집: MathWorks Support Team
2021년 4월 19일
Hi Tord,
The behavior of NaN values in "imagesc" is not defined currently as described in the following documentation: https://www.mathworks.com/help/matlab/ref/imagesc.html#input_argument_c
So that we can work around this behavior for colorbar and data cursor, it will require changing the ticklabels for the former and programming the callback (as per the position of the mouse pointer e.g. if on a NAN tile, display "NaN") for latter. Please refer to the following documentation which can help you implement this behavior:
Cheers!
Nitin
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Orange에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!