分类:
2008-03-03 16:59:28
MATLAB | Plotting in 3 Dimensions |
Plotting |
The creation of three-dimensional graphics is one of the strengths of MATLAB. To give a full description, MATLAB includes a 400 page manual devoted to solely the graphics portion of the program. As a result, this page gives only a very light introduction to what I feel are some of the best features of the three-dimensional graphics commands. In addition, once you have created a three-dimension graphic, the program allows many mouse driven commands, such as live 3d-rotation of the image. The primary method of using MATLAB to create the plot of a three-dimensional surface is the surf command which is used in conjunction with the meshgrid command. Meshgrid creates a matrix of (x , y) points over which the surface is to be plotted. For example
creates two matrices x and y that form 25 points, by using each value in matrix x with the value in the corresponding position in matrix y. The surf command can then be used to draw the surface z =x 2− y2
Note that this gives a surface plotted at 25 data points. To smooth out the surface, add more points to the meshgrid command. You can suppress the output of the matrix by adding a semicolon to the end of the meshgrid command.
One feature of MATLAB that I have not seen in other programs is the colorbar command, which gives a vertical bar indicating the height represented by each color on the surface.
The EdgeColor command can be used to remove the gridlines.
The shading interp (for interpolated) command can be used to further smooth the surface. A single rectangular piece of the surface gradually changes color.
The surfc command also creates a surface but adds a contour plot in the xy plane.
|
Please contact
with your questions, comments, and suggestions.
.
Copyright © 2006 . All rights reserved.