MATLAB: Problem with adjusting custom colormap and colorbar

colorbarcolormapMATLAB

Hello everyone
How to adjust a color bar in this way?
lower than 0.05 = white
0.05 ~ 0.1 = red
0.1 ~ 0.2 = yellow
0.2 ~ 0.3 = green
0.4 ~0.5 = blue
greater than 0.5 = black
Here is my try:
mycolormap = [1 1 1; 1 0 0; 1 1 0; 0 1 0; 0 0 1;0 0 0 ];
colormap (mycolormap)
caxis([0.05, 0.5])
c=colorbar('XTickLabel',{'0.05','0.1','0.2','0.3','0.4','0.5'});
But unfortunately here is my color bar:
which the colors not correctly showing and also color bar tick labels are not consonant.
Thanks

Best Answer

The colormap process is uniform mapping. All bars are the same size. However you can assign the same color to multiple bars.
white
red
yellow
yellow
green
green
blue
blue
black
also note that for mapping purposes, you cannot say "less than" and assign a color to that condition. You need to assign a slot of equal size to the other slots. This can require you to expand your caxis