I fill unused elements in a matrix with NaNs, and I would like to assign a contrasting color to those elements with the NaN value when displaying the data using imagesc.
Below is a link to a possible solution, but I don’t quite understand it.
http://www.mathworks.com/matlabcentral/newsreader/view_thread/19985
NaN values get the first color from the axes colormap, which by default corresponds to the minimum value (other than NaN). You can change the color for minimum value setting axes color limits with CAXIS function. To assign a contrast color to NaN values you can add a special color for NaN values as a first color (1×3 vector).
I take your example and made a function (with some comments):
Here caxis statement assigns the first color of the color map not to the minimum value
amin, but to theamin-dmap. So the first color get assigned specifically to NaNs.Try this function with:
If you comment the ylim statement in the function (can be control with additional parameter) this NaN color will be on the colormap.