MATLAB Examples

3-D Plots

Three-dimensional plots typically display a surface defined by a function in two variables, z = f(x,y) .

To evaluate z, first create a set of (x,y) points over the domain of the function using meshgrid.

[X,Y] = meshgrid(-2:.2:2);
Z = X .* exp(-X.^2 - Y.^2);

Then, create a surface plot.


Both the surf function and its companion mesh display surfaces in three dimensions. surf displays both the connecting lines and the faces of the surface in color. mesh produces wireframe surfaces that color only the lines connecting the defining points.