%% Change the Direction or Pattern of Colors
% When using the default value of C=Z, the colors vary with changes in Z.

[X,Y] = meshgrid(-10:10);
Z = X + Y;
s = surf(X,Y,Z);
xlabel('X');
ylabel('Y');
zlabel('Z');

%
% You can change this behavior by specifying C when you create the surface. For example, the colors on this surface vary with X.

C = X;
s = surf(X,Y,Z,C);
xlabel('X');
ylabel('Y');
zlabel('Z');

%
% Alternatively, you can set the CData property directly. This command makes the colors vary with Y.

s.CData = Y;

%
% The colors do not need to follow changes in a single dimension. In fact, CData can be any array that is the same size as Z. For example, the colors on this plane follow the shape of a sinc function.

R = sqrt(X.^2 + Y.^2) + eps;
s.CData = sin(R)./(R);

% Copyright 2012 The MathWorks, Inc.