Matlab three-dimensional drawing

Source: Internet
Author: User

1. Mesh (Z) statement

Mesh (z) statement can give the matrix z element of the three-dimensional blanking graph, the network surface is defined by the z-coordinate point, and the preceding x-y plane of the same line, the graph is connected by the adjacent points. It can be used to display large matrices with large amounts of data that are difficult to output in other ways, as well as to draw a z-variable function.

The function z=f (x, y) of the two variables is displayed, and the first step is to produce the X-y matrix for a particular row and column . The values of the functions at each grid point are then computed. Finally, the mesh function is used to output.

Below we draw a graph of the sin (r)/R function. To create a graph, use the following methods:

X=-10:1:10;

Y=x ';

X=ones (Size (y)) *x;

Y=y*ones (Size (y)) ';

R=sqrt (x.^2+y.^2) +eps;

Z=sin (R)./R;

Mesh (z) percent trial run mesh (x, y, z) to see what is different from mesh (z)?

The meaning of each statement is: first establish the row vector x, the column vector y, and then the length of the vector to build 1-matrix, multiply the vector by multiplying the resulting 1-matrix, generate mesh matrix, their values correspond to the x-y coordinate plane; Next, calculate the radius of each grid point Finally, the function value matrix Z is computed. The mesh function is used to get the graph.

The first statement X is assigned to the definition field, the function is evaluated on it, the third statement establishes a repeating row of the x matrix, the fourth statement produces the response of Y, and the fifth statement produces the matrix R (whose elements are the distance from each grid point to the origin). the result of using mesh method is as above.

In addition, the first 4 lines in the preceding command series can be replaced by one of the following commands:

[X, Y]=meshgrid ( -10:1:10)

2 MESHC Usage

MESHC is called the same way as the function mesh, except that it adds the function of drawing corresponding contour lines on the basis of mesh. Let's look at a meshc example:

[X,y]=meshgrid ([ -4:.5:4]);

Z=SQRT (x.^2+y.^2);

MESHC (z) percent trial run MESHC (x, Y, z) to see what is different from MESHC (z)?

function meshz and mesh are called the same way, the function of the mesh function on the effect of increasing the shielding effect, that is, the addition of boundary surface shielding. For example:

[X,y]=meshgrid ([ -4:.5:4]);

Z=SQRT (x.^2+y.^2);

Meshz (z) percent trial run meshz (x, Y, z) to see what is different from meshz (z)?

The 3 surf function is also a three-dimensional drawing function commonly used in Matlab . Its invocation format is as follows:

Surf (x,y,z,c)

The input parameters are set in the same way as mesh, but the mesh function draws a grid graph, and surf draws a three-dimensional surface that is shaded. The Matlab language to color the surface of the method is, after the corresponding mesh, each grid according to the grid represents the node's color value (controlled by the variable c), to define the colors of this grid. If you do not enter C, the default is c=z.

Let's look at the following example:

% draws the temperature distribution on the Earth's surface.

[A,b,c]=sphere (40);

T=abs (c); % seek absolute value

Surf (a,b,c,t);

Axis equal

ColorMap (' hot ')

Axis control function axis, the calling format is as follows:

Axis ([Xmin,xmax,ymin,ymax,zmin,zmax])

Use this command to control the range of axes.

several common commands related to axis are:

Axis Auto Auto mode, so that the coordinate range of the graph satisfies all the diagram elements in the graph

Axis equal strictly controls the degree of division of each coordinate to make it equal

Axis Square makes the plot area a square

Axis on restores all settings on the axis

Axis off cancels all settings on the axis

Axis manual limits the drawing of the drawing with the current coordinates

(2)grid on draws the coordinate grid in the drawing.

Grid off cancels the coordinate grid.

(3)Xlabel, Ylabel, Zlabel are labeled X-axis, y-axis, and z-axis respectively . Title adds a caption to the graphic.

The call format of the above function is similar, we take Xlabel as an example to introduce:

Xlabel (' Callout text ',' attribute 1 ',' attribute value 1 ',' attribute 2 ',' property value 2 ',...)

The attributes here are the attributes of the callout text, including font size, font name, font weight, and so on.

For example:

[X, Y]=meshgrid ( -10:1:10);

R=SQRT (x.^2+y.^2);

Z=-cos (R);

Mesh (x, y, z)

Xlabel (' x\in[-4,4] ', ' fontweight ', ' bold ');

Ylabel (' y\in[-4,4] ', ' fontweight ', ' bold ');

Zlabel (' Z=-cos (sqrt (x^2+y^2)) ', ' fontweight ', ' bold ');

Learning the use of these functions, I think it should be enough, the other functions can be consulted at the time of use.

Matlab three-dimensional drawing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.