colors in surf according to values

When I ejecute:
Z = [5 10 10 5
5 10 10 5];
surf(Z)
I get a figure which has three faces, and It colors first face with blue and second and third with yellow. I would like to modify this painting with yellow in last face. My objective is to get figure has colors according to values in Z, that is,
  • 5 to 10 -> blue,
  • 10 to 10 -> yellow, and
  • 10 to 5 -> blue.

 Accepted Answer

You can control surface color by setting color value, like the following. More details can be found in help page of surf function.
C = zeros([size(Z),3]);
C(1,1,:) = [0 0 1]; % blue
C(1,2,:) = [1 1 0]; % yellow
C(1,3,:) = [0 0 1]; % blue
surf(Z,C)

More Answers (0)

Categories

Find more on App Building in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!