MATLAB provides various functions to display 3D images. Some functions can draw lines in 3D space, while others can draw curves and grid frames. In addition, colors can be used to represent the four-dimensional dimension. When a color is used in this way, it is called pseudocolor because it no longer shows the natural attribute of information as in the photo-color, and it is not the internal attribute of basic data. To simplify the discussion of 3D images, the introduction of colors is postponed to the next chapter. In this chapter, we mainly discuss the basic concepts of 3D drawing.
The functions and features discussed below are summarized in table 2, table 3, table 4, and table 5:
Table 2
Contour two-dimensional equivalent line chart, that is to say, from the top down, we can see the contour3 isoplot, and the 3 isoplot, The fill3 filled polygon mesh. The meshc has a basic isogram. The meshz has a zero-plane grid. The pcolor two-dimensional pseudo-color drawing, that is to say, from the top down, the surf graph, the plot3 line graph, the quiver two-dimensional speed graph with a direction arrow, the surf surface graph, the surfc has a basic isoplot, And the surfl has a brightness curve graph. The waterfall has no cross lines.
3
Axis correction axis attribute CLF clear graph window clabel place contour label close graph window figure create or select graph window getframe capture animation 2D grid place grid griddata Interpolation of drawing data hidden concealed Grid graph line hold retains the current figure meshgrid to generate 3D drawing data movie place animation moviein create 2D matrix, storage animation shading in curved surface and pseudo-color graphs use blocks, smoothing, interpolation, and shadow subplot to draw subgraphs in the graphic window text placement in the specified position text title placement title view change the visual angle xlabel placement X axis mark ylabel place Y axis mark zlabel place Z axis mark
Table 4
View (AZ, El) sets the view's Azimuth Az and elevation elview ([AZ, El]) view ([x, y, z]) along the vector in the flute coordinate system [x, y, Z] face up to the origin to set the view, for example, view ([0 0 1]) = view () view (2) set the default two-dimensional view, AZ = 0, el = 90 view (3) set the default 3D view, AZ =-37.5, El = 30 [AZ, El] = view returns the current azimuth Az and elevation elview (t) use a 4 × 4 transpose matrix T to set the view t = view to return the current 4 × 4 transpose matrix
Table 5
Mmcont2 (X, Y, Z, c) two-dimensional isoplot mmcont3 (X, Y, Z, c) with a color image mmspin3d (N) rotate the three-dimensional azimuth of the current image to create an animated mmview3d image. Use slide labels to adjust the angle of view.
In addition, the reshape function of MATLAB gives priority to columns, for example:
Y = 1 2 3 4 5 6
Reshape (Y, 3, 2) =
1 4
2 5
3 6
Instead of 1 2 3
4 5 6
Http://zhanglili011282.blog.163.com/blog/static/816261002008111631157417/
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
1. Direct plot Functions
There are two direct plot functions: Fplot and ezplot.
1. Fplot
Fplot commands are called in the following formats:
(1) Fplot (fun, LIMS, STR, Tol): draws the graph of Function Y = fun (x) directly. LIMS is a vector. If LIMS contains only two elements, the range of the X axis is [xmin, xmax]. If LIMS contains four elements, the first two elements represent the range of the X axis: [xmin, xmax], and the last two elements represent the range of the Y axis: [ymin, Ymax]. STR can specify the line type and color of the image. The value of ToL is less than 1, indicating a relative error. The default value is 0.002, that is, 0.2%.
> Fplot (@ humps, [-]) % draws the humps function within the range [-]
In the preceding command, @ humps refers to referencing a function as a function handle. (C: \ Program Files \ MATLAB \ r2009a \ toolbox \ MATLAB \ demos \ humps. m ).
(2) Fplot (fun, LIMS, n): use at least N + 1 points to draw a function fun image, where n is greater than or equal to 1.
> Fplot ('x ^ 2', [-1 1]) % draws Function Y = x ^ 2 in the range [-]
2. ezplot, ezplot3
The ezplot command is used to draw the independent variable of the symbol expression and the two-dimensional curve corresponding to each function value. The ezplot3 command is used to draw a three-dimensional curve.
(1) curve drawing
Syntax:
Ezplot (F, [xmin, xmax], FIG) % draws the image of the symbol expression F
Note: F is the symbolic function to be drawn. [xmin, xmax] is the range of independent variables for drawing. If this parameter is omitted, the default value is [-2 limit, 2 limit]. fig is the specified graph window. If it is omitted, it is the current graph window by default.
Example:
> Y = Sym ('-1/3 * x ^ 3 + 1/3 * x ^ 4 ')
Y =
-1/3 * x ^ 3 + 1/3 * x ^ 4
> Ezplot (y) % plot the graph of the symbolic function y in [-2 rows, 2 rows]
> Ezplot (Y, [0,100]) % plot the graph of the symbolic function y in [0,100]
Another example
> X = Sym ('sin (t )');
> Y = Sym ('cos (t )');
> Z = Sym ('T ');
> Ezplot3 (X, Y, Z, [* Pi], 'animate') % plot the three-dimensional curve of T in the range of [* Pi]
(2) surface rendering
For example
> Ezmesh ('sin (x) * exp (-T) ', 'cos (x) * exp (-T)', 'x ', [0, 2 * Pi]);
Ezmesh means easy to use 3-D Mesh plotter, so its calling format is simple and easy to draw.
(3) Other drawing commands
MATLAB also provides the following commonly used drawing commands. Examples of these commands are drawing string functions, and can also be used for drawing symbol expressions.
Command name meaning example
Ezcontour draw the contour ezcontour ('x * sin (t) ', [-4, 4])
Ez0000f draws a contour line ez0000f ('x * sin (t) ', [-])
Ezmesh draw a three-line ezmesh ('sin (x) * exp (-T) ', 'cos (x) * exp (-T)', 'x ', [0, 2 * Pi])
Ezmeshc draw a three-dimensional line chart with contour lines ezmeshc ('sin (x) * t', [-Pi, Pi])
Ezpolar polar chart ezpolar ('sin (t) ', [0, PI/2])
Ezsurf 3D curved surface image ezsurf ('x * sin (t) ', 'x * Cos (t)', 't', [* Pi])
Ezsurfc 3D surface map with contour lines ezsurfc ('x * sin (t) ', 'x * Cos (t)', 't', [0, PI, 0, 2 * Pi])
2. Draw a 3D surface using a grid method
1. generate 3D data
In Matlab, The meshgrid function is used to generate a grid coordinate matrix in the plane area. The format is:
X = A: D1: B; y = C: D2: D;
[X, y] = meshgrid (x, y );
After the statement is executed, each row of matrix X is vector X, the number of rows is equal to the number of elements of vector y, and each column of matrix Y is vector y, the number of columns equals the number of elements in vector X.
2. Functions for drawing 3D Surfaces
The Calling formats of the surf and mesh functions are as follows:
Mesh (X, Y, Z, c)
Surf (X, Y, Z, c)
Generally, x, y, and z are matrices with the same dimension. X and Y are grid coordinate matrices, while Z is the height matrix on the grid point. C is used to specify the color range at different heights.
Example:
Use a curved surface map to present functions y = x ^ 2 + y ^ 2.
CLF, x =-4:4; y = x; [x, y] = meshgrid (x, y );
Z = x. ^ 2 + Y. ^ 2;
Surf (x, y, z); % or mesh (x, y, z)