1. 程式人生 > >Matlab 繪製向量圖

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:
       [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)