Chinaunix首页 | 论坛 | 博客
  • 博客访问: 89447
  • 博文数量: 22
  • 博客积分: 2000
  • 博客等级: 大尉
  • 技术积分: 505
  • 用 户 组: 普通用户
  • 注册时间: 2007-11-21 17:13
文章分类

全部博文(22)

文章存档

2011年(1)

2008年(21)

我的朋友

分类:

2008-03-03 16:59:28

from:
 
 
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

[x,y]=meshgrid(-2:1:2,-2:1:2)

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 2y2

surf(x,y,x.^2-y.^2)

rough surface

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.

[x,y]=meshgrid(-2:0.1:2,-2:0.1:2);

surf(x,y,x.^2-y.^2)

smooth surface

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.

colorbar

surface with colorbar

 

 

The EdgeColor command can be used to remove the gridlines.

surf(x,y,x.^2-y.^2,'EdgeColor','none')

surface with grid removed

The shading interp (for interpolated) command can be used to further smooth the surface. A single rectangular piece of the surface gradually changes color.

shading interp

surface with interp shading

The surfc command also creates a surface but adds a contour plot in the xy plane.

surfc(x,y,x.^2-y.^2,'EdgeColor','none)

surface with contour plot


 

 

 

Ohlone College home page
Please contact
with your questions, comments, and suggestions.
.
Copyright © 2006 . All rights reserved.

from:
阅读(550) | 评论(0) | 转发(0) |
0

上一篇:没有了

下一篇:两函数的inner product

给主人留下些什么吧!~~