MATLAB: MESHZ – Change Curtain color.

colorcurtianmeshz

Hello,
I'm making a plot of a terrian using:
g=meshz(XI, YI, ZI);
demcmap(ZI); %Set terrain color
set(g,'FaceColor','interp','EdgeColor','k');
It's posible to change the curtain color without affect the terrian color?
Thanks, Cristian

Best Answer

Yes, it is possible. You can do it by adjusting the CData property of the surface that meshz creates. meshz will create a surface whose CData matrix is just the height values of the surface padded with two extra rows/columns on each side to make the curtain. If you want to change the color of the curtain, you can generate your own CData array. For example:
% Make the initial plot
[x, y, z] = peaks;
g = meshz(x, y, z);
set(g,'FaceColor','interp','EdgeColor','k');
% Generate a new CData matrix by
% allocating a new array that has two extra rows/columns on each
% side. Note that the x, y, and z arrays in this example are 49x49
% Therefore we need C to be 53x53 (53 = 49 + 2 + 2). Obviously this
% could be automated using the SIZE function. The -4 here means that
% the curtain will be colored with whatever color represents -4 in
% the colormap ... you could change this to be whatever works for your
% application.
C = -4 * ones( 53, 53 );
% Insert the Z-data into the matrix.
C(3:51, 3:51) = z;
% Set the property on the surface.
set(g, 'CData', C)
colorbar;
Related Question