MATLAB 3D drawing mainly has three commands: The plot3 command, the mesh command, and the SURF command.
Plot3 is the basic function of 3D drawing. It draws the most important 3D graph. The most important calling format is:
Plot3 (x, y, z)
When x, y, and z are vectors of the same length, the plot3 command will plot a curve with the X, Y, and Z vectors as (x, y, z) coordinate values respectively.
When x, y, and z are all M * n matrices, the plot3 command will plot M curves, with each curve being x, y, and z column vectors (x, y, z) coordinate value curve
The difference between mesh and plot3 is that it can draw a complete surface (grid chart) within a certain range ). The most important call format is:
Mesh (x, y, z)
Note that X and Y must be vectors. If the lengths of X and Y are M and N respectively, Z must be a matrix of M * n, that is, [m, n] = size (Z). In this case, the vertex of the gridline is(X (J), y (I), Z (I, j ))
The calling method of surf is similar to the mesh command. The difference is that the image drawn by the mesh function is a mesh image, while the surf command draws a colored three-dimensional surface. After obtaining the corresponding grid, the color of the grid is defined for each grid based on the color value of the nodes represented by the grid. The most basic call format is:
Surf (x, y, z)
Note: first, surf only supports Cartesian coordinate systems (Cartesian coordinate systems ). Second, if you want to smooth the surface and remove the mesh, you only need to add the following after the drawing command:Shading interp. In this way, Matlab performs corresponding interpolation. Assume that you want to create a two-dimensional graph to simulate the effect of a 3D graph. Now, you can manually rotate the 3D graph into a two-dimensional graph and then add a colorbar.
The figure below shows the effect of removing the surf command from the grid.
Manually rotate and add a two-dimensional chart after the colorbar: