You are currently browsing the Carl's notes weblog archives for August, 2011.

Displaying covariance matrices as heatmaps in Matlab

Large covariance matrices can be difficult to interpret, and this isn’t helped by the fact that they don’t always fit on the screen due to their size or display properly due to a wide range of values.

In Matlab, you can display a covariance matrix P as a heatmap with the command imagesc(P). This will display a grid the same size as your matrix, with the colour of each cell chosen according to the corresponding value in your matrix. With the default colour map the lowest value will be dark blue and the highest value dark red. Different colour maps can be set with the colormap command. Display the colour bar beside your figure to get a reminder of actual values. Some covariance matrices contain a mix of units and some values will be so large that they mask others. In this case you may need to manually normalise P or split it into several blocks with a consistent range of values.

I’d been wondering how to do this for ages and found the idea on one of the Mathworks forums. Thanks Warren.