Documentation

quiver

Quiver or velocity plot Syntax

quiver(x,y,u,v)
quiver(u,v)
quiver(...,scale)
quiver(...,LineSpec)
quiver(...,LineSpec,'filled')
quiver(...,'PropertyName',PropertyValue,...)
quiver(ax,...)
h = quiver(...)

Description

A quiver plot displays velocity vectors as arrows with components (u,v) at the points (x,y).

For example, the first vector is defined by components u(1),v(1) and is displayed at the point x(1),y(1).

quiver(x,y,u,v) plots vectors as arrows at the coordinates specified in each corresponding pair of elements in x and y. The matrices x, y, u, and v must all be the same size and contain corresponding position and velocity components. However, x and y can also be vectors, as explained in the next section. By default, the arrows are scaled to just not overlap, but you can scale them to be longer or shorter if you want.

quiver(u,v) draws vectors specified by u and v at equally spaced points in the x-y plane.

quiver(...,scale) automatically scales the arrows to fit within the grid and then stretches them by the factor scale. scale = 2 doubles their relative length, and scale = 0.5 halves the length. Use scale = 0 to plot the velocity vectors without automatic scaling. You can also tune the length of arrows after they have been drawn by choosing the Plot Edit tool, selecting the quiver object, opening the Property Editor, and adjusting the Length slider.

quiver(...,LineSpec) specifies line style, marker symbol, and color using any valid LineSpec. quiver draws the markers at the origin of the vectors.

quiver(...,LineSpec,'filled') fills markers specified by LineSpec.

quiver(...,'PropertyName',PropertyValue,...) specifies property name and property value pairs for the quiver objects the function creates.

quiver(ax,...) plots into the axes ax instead of into the current axes (gca).

h = quiver(...) returns the Quiver object.

Expanding x- and y-Coordinates

MATLAB® expands x and y if they are not matrices. This expansion is equivalent to calling meshgrid to generate matrices from vectors:

[x,y] = meshgrid(x,y);
quiver(x,y,u,v)

In this case, the following must be true:

length(x) = n and length(y) = m, where [m,n] = size(u) = size(v).

The vector x corresponds to the columns of u and v, and vector y corresponds to the rows of u and v.

Examples

collapse all

Use quiver to display an arrow at each data point in x and y such that the arrow direction and length represent the corresponding values in u and v.

[x,y] = meshgrid(0:0.2:2,0:0.2:2);
u = cos(x).*y;
v = sin(x).*y;

figure
quiver(x,y,u,v) Plot the gradient of the function $z=x{e}^{-{x}^{2}-{y}^{2}}$.

[X,Y] = meshgrid(-2:.2:2);
Z = X.*exp(-X.^2 - Y.^2);

figure
contour(X,Y,Z)
hold on
quiver(X,Y,DX,DY)
hold off 