Next: Animation Up: 3-D Previous: Line Plots

### Surface Plots

Both surf and mesh plot a two-dimensional curve in 3-D; surf facets the surface, while mesh plots the facet outlines only. They are identical otherwise, including in taking arguments. There are variants; surfc and meshc include a contour plot (see help contour), surfl provides lighting, meshz provides a reference plane, and waterfall gives a mesh without column lines.

The most general argument to surf is a vector of four matrices, e.g. surf(X, Y, Z, C). The first three matrices give the 3-D coordinates of each point on the surface, and the last gives its color as per the current colormap. Omitting the last, e.g. surf(X, Y, Z), uses C = Z, i.e. color is proportional to height.

The X and Y matrices can be replaced by vectors of the width and height of Z; both or neither must be replaced. A X matrix is then used with the x vector as each row, and a Y matrix with the y vector as each column. If X and Y are omitted entirely, the vectors 1:width and 1:height are used instead.

To evaluate a function that can be performed elementwise on a matrix over a grid of points on the plane and plot it at even intervals, use meshgrid to create X and Y matrices from vectors with [X, Y] = meshgrid(x, y) (all the rows of X are x, all the columns of Y are y). Then e.g. Z = X. Y and mesh(Z) will display (in this case) the coordinate products, but at evenly spaced intervals as the x and y vectors did not directly reach mesh.

Portions of a surface plot may be hidden behind others. One method of dealing with this is to change the viewpoint; see help view. Alternatively, since MATLAB does not plot values of NaN and Inf, you can make ``cutouts'' in a plot by setting the color value on some region of facets to one of those.

Other features of 3-D plots can be set with caxis, colormap, shading, and view, and various color functions, for all of which see the help entries, as well as the commands described above for 2-D plots.

Next: Animation Up: 3-D Previous: Line Plots

sepherke
Sat Mar 21 21:42:28 EST 1998