www.gusucode.com > graphics 案例源码程序 matlab代码 > graphics/CreateSurfacePlotExample.m

    %% Create Surface Plot 
% Plot the function $z = x e^{-x^2 -y^2}$ on the domain $-2 \leq x \leq
% 2$ and  $-2 \leq y \leq 2$. Use |meshgrid| to define |X| and |Y|.
% Then, define |Z| and create a surface plot. Change the view of the plot
% using |view|.

% Copyright 2015 The MathWorks, Inc.


%%
[X,Y] = meshgrid(-2:0.2:2,-2:0.2:2);
Z = X.*exp(-X.^2 - Y.^2);
figure
surface(X,Y,Z)
view(3)

%%
% |surface| creates the plot from corresponding values in |X|, |Y|, and
% |Z|. If you do not define the color data |C|, then |surface| uses |Z| to determine the
% color, so color is proportional to surface height.