MATLAB: Edit colorbar of heatmap (string)

colorbarcolormapdesignheatmapMATLABplotplottingyticklabel

Hi,
Is it possible to edit the colorbar of a heatmap such that it looks like the following image (rapidly created with paint 😉 )
a.PNG
So the values aren't numeric but strings.
Thanks for help!

Best Answer

This can't be done with heatmap() (see comments under the question).
If you're using a different function that allows access to the colobar, it's fairly straightforward. Here's a demo.
% Create demo
C = rand(3,4)/10;
imagesc(C)
cbh = colorbar();
% set color range
caxis([0,.1])
% set ticks
set(cbh, 'YTick', [0.001, 0.01, 0.05, .1], ...
'YTickLabel', {'p=0.001', 'p=0.01', 'p=0.05', 'p=.1'})