MATLAB: Color map from green to red

colorcolormapimage analysisimage processing

Hi all,
I have a map with values and i would like to display the values with colors – from green to red.
The value closest to 0 will be green and the farthest will be red.
Example:
1, 5, 11, 33, 56, 100
1 – Green.
100 – Red.
Can be also:
-5, -23, -43, -55, -80.
-5 – Green.
-80 – Red.
The rest values will be in the order and color bar.

Best Answer

You can create your original colormap (green to red) and apply to the data.
The following is an example:
% Create green-to-red colormap
cMap = interp1([0;1],[0 1 0; 1 0 0],linspace(0,1,256));
% Apply to the plot
surf(peaks)
colormap(cMap)
colorbar
Related Question