Anonymous 发表于 2013-3-21 18:20:19

matlab绘制矢量

经常会用到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:
= meshgrid(-2:.2:2,-1:.15:1);
z = x .* exp(-x.^2 - y.^2); = gradient(z,.2,.15);
contour(x,y,z), hold on
quiver(x,y,px,py), hold off, axis image
例如要绘制
zx 为x方向矢量
zy 为y方向矢量
(minx, maxx)为x方向取值区间
(miny, maxy)为y方向取值区间
=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;
>> =meshgrid(-2:0.2:2,-3:0.4:3);
>> Z=X.*exp(-X.^2-Y.^2);
>> =gradient(Z,0.2,0.4);
>> contour(X,Y,Z);
>> hold on;
>> quiver(X,Y,DX,DY);
>> colormap hsv;
>> hold off;

>> =meshgrid(-2:0.2:2,-2:0.2:2);
>> z=x.^2+y.^2;
>> contour(x,y,z);
>> =gradient(z,0.2,0.2);
>> hold on;
>> quiver(x,y,dx,dy);
页: [1]
查看完整版本: matlab绘制矢量