MATLAB: I have a map of different colors, I need all z values from greater than 0 to be red, all zero values to be white, and all below zero values to be blue

colorcolorbarcolormapgraphplot

color specifications
imagesc(z)
cmap = [1 0 0 ; 0 1 0 ; 0 0 1] ;
colorbar
colormap(cmap)
I applied the code above, but it just seperated the ranges equaly.

Best Answer

Zz = (z>0) - (z<0);
imagessc(Zz)
colormap(cmap)
caxis([-1,1])
The caxis is there for protection in case z does not have a mix of negative and positive values.
If there can be nan in z then
Zz(isnan(z)) = nan;