物探论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 1159|回复: 0

[其它] matlab绘制矢量

[复制链接]
匿名
匿名  发表于 2013-3-21 18:20:19 |阅读模式
经常会用到matlab计算矢量图,我们希望可以直观的表示出来,通过观察来对比。
因此,希望可以绘制出矢量图。
matlab提供了矢量图绘制函数:quiver()
matlab help给出了说明:
QUIVER Quiver plot.
QUIVER(X,Y,U,V) plots velocity vectors as arrows with components (u,v)
at the points (x,y). The matrices X,Y,U,V must all be the same size
and contain corresponding position and velocity components (X and Y
can also be vectors to specify a uniform grid). QUIVER automatically
scales the arrows to fit within the grid.

QUIVER(U,V) plots velocity vectors at equally spaced points in
the x-y plane.

QUIVER(U,V,S) or QUIVER(X,Y,U,V,S) automatically scales the
arrows to fit within the grid and then stretches them by S. Use
S=0 to plot the arrows without the automatic scaling.

QUIVER(...,LINESPEC) uses the plot linestyle specified for
the velocity vectors. Any marker in LINESPEC is drawn at the base
instead of an arrow on the tip. Use a marker of '.' to specify
no marker at all. See PLOT for other possibilities.

QUIVER(...,'filled') fills any markers specified.

QUIVER(AX,...) plots into AX instead of GCA.

H = QUIVER(...) returns a quivergroup handle.

Backwards compatibility
QUIVER('v6',...) creates line objects instead of a quivergroup
object for compatibility with MATLAB 6.5 and earlier.

Example:
[x,y] = meshgrid(-2:.2:2,-1:.15:1);
z = x .* exp(-x.^2 - y.^2); [px,py] = gradient(z,.2,.15);
contour(x,y,z), hold on
quiver(x,y,px,py), hold off, axis image
例如要绘制[zx,zy]
zx 为x方向矢量
zy 为y方向矢量
(minx, maxx)为x方向取值区间
(miny, maxy)为y方向取值区间
[xx,yy]=meshgrid(minx:maxx, miny:maxy);
quiver(xx,yy,zx,zy)
这儿有一个不是极坐标的,你参考一下:
简单的一个三维矢量图
各点的加速度方向
vz=10;
a=-32;
t=0:0.1:1;
z=vz*t+1/2*a*t.^2;
vx=2;
x=vx*t;
vy=3;
y=vy*t;
u=gradient(x);
v=gradient(y);
w=gradient(z);
quiver3(x,y,z,u,v,w)
又一个例子:
>> clear all;
>> [X,Y]=meshgrid(-2:0.2:2,-3:0.4:3);
>> Z=X.*exp(-X.^2-Y.^2);
>> [DX,DY]=gradient(Z,0.2,0.4);
>> contour(X,Y,Z);
>> hold on;
>> quiver(X,Y,DX,DY);
>> colormap hsv;
>> hold off;

>> [x,y]=meshgrid(-2:0.2:2,-2:0.2:2);
>> z=x.^2+y.^2;
>> contour(x,y,z);
>> [dx,dy]=gradient(z,0.2,0.2);
>> hold on;
>> quiver(x,y,dx,dy);
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|物探论坛 ( 鄂ICP备12002012号 微信号:iwutan )

GMT+8, 2024-5-4 11:39 , Processed in 0.061116 second(s), 15 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表