MATLAB: Highlight cells in heatmap

heatmapMATLAB

I created a heatmap where each cell represents a temperature value using the commands:
cdata = [values of temperature]
xvalues = [0,1,2,3,etc.]
yvalues = [0,1,2,3,etc.]
h = heatmap(xvalues,yvalues,cdata)
I need to:
  • command to highlight cells over a limit (for example 500)
  • Highlight cells within a given range (for example 300 to 800)
It is not important how the cells are highlighted, it can be a different colour (like green or blue), or a cross X on top of the cells.
Thanks for the help

Best Answer

You can do so by creating a custom colormap. The code below shows a simple implementation.
xvalues = 1:5;
yvalues = 1:5;
cdata = randi(20,[5,5]); % range of values in cells < 20
cmap = [repmat([1 0 0],5,1)
repmat([1 1 1],5,1) % highlight all cells with values from 5-10 with white
repmat([0 0 0],10,1)]; % highlight all cells > 10 with black
heatmap(1:5,1:5,randi(20,[5 5]),'Colormap',cmap);