quiver3Load sample data that represents air currents over North America. For this example, select a subset of the data.
load wind X = x(5:10,20:25,6:10); Y = y(5:10,20:25,6:10); Z = z(5:10,20:25,6:10); U = u(5:10,20:25,6:10); V = v(5:10,20:25,6:10); W = w(5:10,20:25,6:10);
Create a 3-D quiver plot of the subset you selected. The vectors
X,Y, andZrepresent the location of the base of each arrow, andU,V, andWrepresent the directional components of each arrow. By default, thequiver3function shortens the arrows so they do not overlap. Callaxis equalto use equal data unit lengths along each axis. This makes the arrows point in the correct direction.
quiver3(X,Y,Z,U,V,W) axis equal fig2plotly()
By default, the
quiver3function shortens arrows so they do not overlap. To disable automatic scaling so that arrow lengths are determined entirely byU,V, andW, set thescaleargument to0.For example, first return the x-, y-, and z-coordinates of a unit sphere with 10-by-10 faces. Calculate the directional components of its surface normals using the
surfnormfunction. Then, create a 3-D quiver plot with no automatic scaling.
[X,Y,Z] = sphere(10); [U,V,W] = surfnorm(X,Y,Z); quiver3(X,Y,Z,U,V,W,0) axis equal fig2plotly()
For comparison, create the plot with automatic scaling. Note that the arrows are shorter and do not overlap.
figure quiver3(X,Y,Z,U,V,W) axis equal fig2plotly()
Plot vectors that are normal to the surface defined by the function z=xe-x2-y2. Use the
quiver3function to plot the vectors and thesurffunction to plot the surface.First, create a grid of x- and y-values that are equally spaced. Use them to calculate z. Then, find the normal vectors.
[X,Y] = meshgrid(-2:0.25:2,-1:0.2:1); Z = X.*exp(-X.^2 - Y.^2); [U,V,W] = surfnorm(X,Y,Z); fig2plotly()
Display the vectors as a 3-D quiver plot. Then, display the surface in the same axes. Adjust the display so that the vectors appear normal to the surface by calling
axis equal.
quiver3(X,Y,Z,U,V,W) hold on surf(X,Y,Z) axis equal fig2plotly()
Create a 3-D quiver plot and specify a color for the arrows.
For example, first return the x-, y-, and z- coordinates of a surface. Calculate the directional components of its surface normals using the
surfnormfunction.
[X,Y] = meshgrid(-pi/2:pi/8:pi/2,-pi/2:pi/8:pi/2); Z = sin(X) + cos(Y); [U,V,W] = surfnorm(Z);
Then, create a 3-D quiver plot with red arrows.
quiver3(X,Y,Z,U,V,W,'r') axis equal fig2plotly()
Starting in R2019b, you can display a tiling of plots using the
tiledlayoutandnexttilefunctions. Call thetiledlayoutfunction to create a 1-by-2 tiled chart layout. Call thenexttilefunction to create an axes object and return the object asax1. Create the left plot by passingax1to thequiver3function. Add a title to the plot by passing the axes to thetitlefunction. Repeat the process to create the right plot.
[X,Y] = meshgrid(-2:0.25:0,-2:0.25:0); Z1 = -0.5*(X.^2 + Y.^2); [U1,V1,W1] = surfnorm(Z1); Z2 = -X.*Y; [U2,V2,W2] = surfnorm(Z2); tiledlayout(1,2) % Left plot ax1 = nexttile; quiver3(ax1,X,Y,Z1,U1,V1,W1) axis equal title(ax1,'Left Plot') % Right plot ax2 = nexttile; quiver3(ax2,X,Y,Z2,U2,V2,W2) axis equal title(ax2,'Right Plot') fig2plotly()
Create a 3-D quiver plot and return the quiver object. Then, remove the arrowheads and add dot markers at the base of each arrow.
[X,Y] = meshgrid(-3:0.5:3,-3:0.5:3); Z = 0.2*(Y.^2 - X.^2); [U,V,W] = surfnorm(Z); q = quiver3(X,Y,Z,U,V,W); axis equal q.ShowArrowHead = 'off'; q.Marker = '.'; fig2plotly()