MATLAB Functions | Help Desk |
surf, surfc
3-D shaded surface plotsurf(Z) surf(X,Y,Z) surf(...,C) surfc(...) h = surf(...) h = surfc(...)You use
surf
and surfc
to view mathematical functions over a rectangular region. surf
and surfc
create colored parametric surfaces specified by X
, Y
, and Z
, with color specified by Z
or C
.
surf(Z)
creates a a three-dimensional shaded surface from the z components in matrix Z
, using x
=
1:n
and y
=
1:m
, where [m,n] = size(Z)
. The height, Z
, is a single-valued function defined over a geometrically rectangular grid. Z
specifies the color data as well as Surface height, so color is proportional to surface height.
surf(X,Y,Z)
creates a shaded Surface using Z
for the color data as well as Surface height. X
and Y
are vectors or matrices defining the x and y components of a Surface. If X
and Y
are vectors, length(X)
=
n
and length(Y)
=
m
, where [m,n]
=
size(Z)
. In this case, the vertices of the Surface faces are
triples.
surf(...,C)
creates a shaded surface, with color defined by C
. MATLAB performs a linear transformation on this data to obtain colors from the current colormap.
surfc(...)
draws a contour plot beneath the Surface.
h = surf(...) and h = surfc(...)
return a handle to a Surface graphics object.
Abstractly, a parametric surface is parametrized by two independent variables, i
and j
, which vary continuously over a rectangle, for example, 1
i
m
and 1
j
n
. The three functions, x(i,j)
, y(i,j)
, and z(i,j)
specify the surface. When i
and j
are integer values, they define a rectangular grid with integer grid points. The functions x(i,j)
, y(i,j)
, and z(i,j)
become three m
-by-n
matrices, X
, Y
and Z
. Surface color is a fourth function, c(i,j)
, denoted by matrix C
.
Each point in the rectangular grid can be thought of as connected to its four nearest neighbors:
i-1This underlying rectangular grid induces four-sided patches on the surface. To express this another way,,
j | i,
j-1 - i,
j - i,
j+1 | i+1,
j
[X(:)
Y(:)
Z(:)]
returns a list of triples specifying points in 3-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.
Surface color can be specified 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 x
and y
. Moreover, the four-sided surface patches need not be planar. For example, you can have surfaces defined in polar, cylindrical, and spherical coordinate systems.
The shading
function sets the shading. If the shading is interp
, C
must be the same size as X
, Y
, and Z
; it specifies the colors at the vertices. The color within a surface patch is a bilinear function of the local coordinates. If the shading is faceted
(the default) or flat
, C(i,j)
specifies the constant color in the surface patch:
(iIn this case,,
j) - (i,
j+1) | C(i,
j) | (i+1,
j) - (i+1,
j+1)
C
can be the same size as X
, Y
, and Z
and its last row and column are ignored, Alternatively, its row and column dimensions can be one less than those of X
, Y
, and Z
.
The surf
and surfc
functions specify the view point using view(3)
.
The range of X
, Y
, and Z
, or the current setting of the Axes XLimMode
, YlimMode
, and ZlimMode
properties (also set by the axis
function) determine the axis labels.
The range of C
, or the current setting of the Axes CLim
and ClimMode
properties (also set by the caxis
function) determine the color scaling. The scaled color values are used as indices into the current colormap.
Display a surface and contour plot of the peaks
surface:
[XColor a sphere with the pattern of +1s and -1s in a Hadamard matrix:,
Y] = meshgrid(-3:.125:3); Z = peaks(X,
Y);surfc(X,Y,Z)
axis([-3 3 -3 3 -10 5])
k = 5; n = 2^k-1; [x,
y,
z] =sphere
(n); c =hadamard
(2^k); surf(x,
y,
z,
c); colormap([1 1 0; 0 1 1]) set(gca
,'Stretch','off')
axis
, caxis
, colormap
, contour
, mesh
, pcolor
, shading
, view
Properties for Surface
graphics objects.