You can manually set the position of ticks on the colorbar axis by using the CAXIS function to set the color axis limits, and setting the 'YLim' and 'YTick' properties of the colorbar, as shown in the following example:
A = ceil(5*rand(5,7));
imagesc(A);
numcolors = 5;
colormap(jet(numcolors));
caxis([1 numcolors]);
cbarHandle = colorbar('YTick',...
[1+0.5*(numcolors-1)/numcolors:(numcolors-1)/numcolors:numcolors],...
'YTickLabel',int2str([1:numcolors]'), 'YLim', [1 numcolors]);
Best Answer