3-D shaded surface plot
h = surf(...)
surf(Z) creates a three-dimensional
shaded surface from the z components in matrix
[m,n] = size(Z). The height,
is a single-valued function defined over a geometrically rectangular
Z specifies the color data, as well as surface
height, so color is proportional to surface height.
surf(Z,C) plots the height
Z, a single-valued function defined over a geometrically
rectangular grid, and uses matrix
C, assumed to
be the same size as
Z, to color the surface. See Coloring
Mesh and Surface Plots for information on defining
the color data and surface height.
vectors or matrices defining the
of a surface. If
In this case, the vertices of the surface faces are (X(j),
Y(i), Z(i,j)) triples. To create X and Y matrices for arbitrary
domains, use the
define color. MATLAB® performs a linear transformation on this
data to obtain colors from the current colormap.
specifies surface properties along with the data. For a list of properties,
see Chart Surface Properties.
into the axes with handle
axes_handle instead of
the current axes (
h = surf(...) returns a
handle to a chart surface graphics object.
peaks function to define
Z as 25-by-25 matrices. Then, create a surface plot.
[X,Y,Z] = peaks(25); figure surf(X,Y,Z);
surf creates the surface plot from corresponding values in
Z. If you do not define the color data
Z to determine the color, so color is proportional to surface height.
Create a sphere and color it using the pattern from a Hadamard matrix, which is a matrix that contains the values
-1. Change the colors used in the plot by setting the colormap to an array of two RGB triplet values.
k = 5; n = 2^k-1; [x,y,z] = sphere(n); c = hadamard(2^k); figure surf(x,y,z,c); colormap([1 1 0; 0 1 1]) axis equal
surf does not accept complex inputs.
Consider a parametric surface parameterized by two independent
j, which vary
continuously over a rectangle; for example,
The three functions
z(i,j) specify the surface. When
integer values, they define a rectangular grid with integer grid points.
z(i,j) become three
Z. Surface color is a fourth function,
denoted by matrix
Each point in the rectangular grid can be thought of as connected to its four nearest neighbors.
i-1,j | i,j-1 - i,j - i,j+1 | i+1,j
This underlying rectangular grid induces four-sided patches
on the surface. To express this another way,
a list of triples specifying points in 3-D space. Each interior point
is connected to the four neighbors inherited from the matrix indexing.
Points on the edge of the surface have three neighbors. The four points
at the corners of the grid have only two neighbors. This defines a
mesh of quadrilaterals or a quad-mesh.
You can specify surface color in two different ways: at the
vertices or at the centers of each patch. In this general setting,
the surface need not be a single-valued function of
Moreover, the four-sided surface patches need not be planar. For example,
you can have surfaces defined in polar, cylindrical, and spherical
shading function sets the shading.
If the shading is
be the same size as
it specifies the colors at the vertices. The color within a surface
patch is a bilinear function of the local coordinates. If the shading
faceted (the default) or
the constant color in the surface patch:
(i,j) - (i,j+1) | C(i,j) | (i+1,j) - (i+1,j+1)
In this case,
C can be the same size as
Z and its last row and column are ignored.
Alternatively, its row and column dimensions can be one less than
surf function specifies the viewpoint
The range of
C or the current setting of
properties determines the color scaling. You can also set the properties
caxis function. The scaled color values
are indices into the current colormap.