MESHZ - Change Curtain color.

3 views (last 30 days)
Cristian D
Cristian D on 12 Sep 2011
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

Accepted Answer

Patrick Kalita
Patrick Kalita on 15 Sep 2011
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;
  2 Comments
Cristian D
Cristian D on 15 Sep 2011
Thank you Patrick,
I will try it this weekend!. It's posible to change the current map color in order to an specific value take an specific color? For example: turn -4 value to black without change the rest of the colormap.
Regards,
Cristian
Patrick Kalita
Patrick Kalita on 16 Sep 2011
Sure, one thing you could try is adding that color to the bottom of the colormap:
newColormap = [0 0 0; get(gcf, 'Colormap')]
set(gcf, 'Colormap', newColormap);
Then instead of -4 choose a value that is at least as small as any of the other values in the CData array ( e.g. min(ZI(:)) )... or -Inf, that will always use the bottom color of the colormap.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!