Assigning different color to NaN values in 2D matrix
Show older comments
I have a 2D matrix (600x500) which has different values ranging from 0 to 30 and some NaN values. I need to show it as a color image with each pixel having a code code corresponding to its value. I am doing this with imagesc/pcolor.
However, I need to show the NaN values in a completely different color, say white or black to differentiate them from rest of the elements in the matrix. How do I do this?
At present, the NaN values are getting interpreted as zeros and are being shown as the same color as zero.
3 Comments
Sayan
on 25 Apr 2013
Matt Kindig
on 25 Apr 2013
I think your -1 trick is the right way to go. To force those values to be white (or black), you can define a custom colormap for your imagesc/pcolor call. For example:
mycolormap = [ ones(1,3); jet(30)]; %tack on a white row to your colormap
imagesc(...) %or pcolor(...)
colormap(mycolormap); %call your custom colormap
You could also overlay whatever you want to indicate these locations, e.g.
imagesc(data) ;
[r,c] = find(isnan(data)) ;
hold on ;
plot(c, r, 'ro') ;
Accepted Answer
More Answers (0)
Categories
Find more on Color and Styling in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!