MATLAB: Create a surface plot with colors associated to value on cell

colorsgraphicssurface

I have a matrix with 3 possible values: 1, 0 and -1. They may contain any combination of those elements. I'd like to choose the colors for each value (like blue for 1, gray for 0 and red for -1).
When I try surface(matrix), it's not possible to differ: surface(ones(X)) surface(zeros(X)) surface(-ones(X))
Any idea on how to get on with it?

Best Answer

Check out "colormap" in the Matlab Help Navigator. Right under the "Description" section, they talk about creating your own color map. You would define your color map such that the RGB values result in the desired colors to be applied to your surface plot.
Use colormap if you want to choose your own colors...
a=[1 1 -1;0 0 1;-1 -1 1;-1 -1 1];
cmap = [1,0,0;0.5,0.5,0.5;0,0,1]; % 1st row = red; 2nd = gray; 3rd = blue
imagesc(a);
colormap(cmap);