The color right now is changed according to v...
That's why the color in the middle shows up.
More per clarification
Build another array, C, that will be an index into the colormap:
[x,y,z] = meshgrid(-2:.2:2,-2:.25:2,-2:.16:2);
v = x.*exp(-x.^2-y.^2-z.^2);
xslice = [-1.2,.8,2]; yslice = 2; zslice = [-2,0];
C = ones(size(v));
C((v > 0) & (v < 0.2)) = 2;
C(v>=0.2) = 3;
colormap([0 0 1;0 1 0;1 0 0]);
slice(x,y,z,C,xslice,yslice,zslice)
Best Answer