A little while ago I found myself needing to plot a heat map table in MATLAB. Such a plot is a table where the cells have background colors; the colors depend on the value in the cell, e.g. a higher value could correspond with a warmer color. I found no existing function to do this easily, so I set out to create my own solution.

The code to plot a heat map table can be found here.

Usage is pretty simple. If you have a matrix , just pass it into the function and it will do the rest! For example:

1 2 3 4 5 6 7 |
A = zeros(7,7); for i = 1:7 for j = 1:7 A(i,j) = i+j-2; end end tabularHeatMap(A); |

There are a number of options available. See the documentation in the code for more information about the options. To further adjust the generated figure, such as to add labels, proceed as you would with other plotting functions. For example:

1 2 3 4 5 6 7 8 9 10 |
confusion = crosstab(responses, correctAnswers); h = tabularHeatMap(confusion, 'Colormap', 'winter'); title('Confusion Matrix'); xlabel('Correct'); ylabel('Response'); h.XAxisLocation = 'top'; h.XTick = [1 2 3]; h.XTickLabel = {'A', 'B', 'C'}; h.YTick = [1 2 3]; h.YTickLabel = {'A', 'B', 'C'}; |