Home give a color to not a number
Reply: 2

give a color to not a number

ErroriSalvo
1#
ErroriSalvo Published in 2017-12-07 11:10:30Z

I have a matrix of integers, padded with nans

M=

 1     2     2     3     4     4
 2     2     2     3     4   NaN
 2     2     2     3     4   NaN
 2     2     2     3     4   NaN
 2     2     2     3     4   NaN
 2     2     2     3     4   NaN

I am plotting it using imagesc

imagesc(M)

However, if I plot it this way, NaN and 1 are shown with the same color, which is confusing.

How to have different colors for NaNs in imagesc?

matlabgui
2#
matlabgui Reply to 2017-12-07 11:13:28Z

One way to do it is to set the NaN to be transparent:

figure; imagesc ( M, 'alphadata', ~isnan(M) )
Luis Mendo
3#
Luis Mendo Reply to 2017-12-07 11:24:43Z

You can replace NaN by 1 less than the minimum number in M:

t = M;
t(isnan(M)) = min(M(:))-1;
imagesc(t)

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.34113 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO