# Documentation of quiver_barb

Global Index (all files) (short | long) | Local Index (files in subdir) (short | long)

## Function Synopsis

`[hh] = quiver(varargin)`

## Help text

```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 vecocity 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.

H = QUIVER(...) returns a vector of line handles.

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

```

## Cross-Reference Information

This function calls This function is called by

## Listing of function quiver_barb

```function [hh] = quiver(varargin)

%   Clay M. Thompson 3-3-94
%   Copyright (c) 1984-98 by The MathWorks, Inc.
%   \$Revision: 5.15 \$  \$Date: 1997/11/21 23:46:38 \$

%alpha = 0.33; % Size of arrow head relative to the length of the vector
%beta = 0.33;  % Width of the base of the arrow head relative to the length
alpha = 0.25;
beta = 0.25;
autoscale = 1; % Autoscale if ~= 0 then scale by this.
plotarrows = 1; % Plot arrows
sym = '';

filled = 0;
barb = 0;
ls = '-';
ms = '';
col = 'k';

nin = nargin;
% Parse the string inputs
while isstr(varargin{nin}),
vv = varargin{nin};
if ~isempty(vv) & strcmp(lower(vv(1)),'f')
filled = 1;
nin = nin-1;
elseif ~isempty(vv) & strcmp(lower(vv(1)),'b');
barb = 1
plotarrows = 0
nin = nin-1;
else
[l,c,m,msg] = colstyle(vv);
if ~isempty(msg),
error(sprintf('Unknown option "%s".',vv));
end
if ~isempty(l), ls = l; end
if ~isempty(c), col = c; end
if ~isempty(m), ms = m; plotarrows = 0; end
if isequal(m,'.'), ms = ''; end % Don't plot '.'
nin = nin-1;
end
end

error(nargchk(2,5,nin));

% Check numeric input arguments
if nin<4, % quiver(u,v) or quiver(u,v,s)
[msg,x,y,u,v] = xyzchk(varargin{1:2});
else
[msg,x,y,u,v] = xyzchk(varargin{1:4});
end
if ~isempty(msg), error(msg); end

if nin==3 | nin==5, % quiver(u,v,s) or quiver(x,y,u,v,s)
autoscale = varargin{nin};
end

% Scalar expand u,v
if prod(size(u))==1, u = u(ones(size(x))); end
if prod(size(v))==1, v = v(ones(size(u))); end

if autoscale,
% Base autoscale value on average spacing in the x and y
% directions.  Estimate number of points in each direction as
% either the size of the input arrays or the effective square
% spacing if x and y are vectors.
if min(size(x))==1, n=sqrt(prod(size(x))); m=n; else [m,n]=size(x); end
delx = diff([min(x(:)) max(x(:))])/n;
dely = diff([min(y(:)) max(y(:))])/m;
del = min([delx dely]);
len = sqrt(u.^2 + v.^2)/del;
autoscale = autoscale*0.9 / max(len(:));
len = len*autoscale;

% Extend this so a small vector can be drawn at the bottom of the screen

%  if nargout > 1
%    a = [1 1/autoscale] * mean(sqrt(u(:).^2 + v(:).^2));
%    u = [NaN*ones(2,n); u];
%    v = [NaN*ones(2,n); v];
%    y = [[([min(y(:))-2*dely; min(y(:))-dely]) * ones(1, n)]; y];
%    x = [x(1:2,:); x];
%    if n >= 4
%      u(2, n-3) = -1*a(1);
%    else
%      disp('n < 4, so no arrow drawn.  You can change this if you want');
%    end
%  end

b = [min(x(:)) max(x(:)) min(y(:)) max(y(:))];

end

ax = newplot;
next = lower(get(ax,'NextPlot'));
hold_state = ishold;

% Make velocity vectors

%  First, get angle:
x = x(:).'; y = y(:).';
u = u(:).'; v = v(:).';

if barb;
len = 0.95*del*ones(size(len));
end
len = len(:).';

ang = atan2(v, u);
if ~barb;
uu = [x;x+len.*cos(ang);repmat(NaN,size(u))];
vv = [y;y+len.*sin(ang);repmat(NaN,size(u))];
h1 = plot(uu(:),vv(:),[col ls]);
else
uu = [x;x-len.*cos(ang);repmat(NaN,size(u))];
vv = [y;y-len.*sin(ang);repmat(NaN,size(u))];
h1 = plot(uu(:),vv(:),[col ls]);
end
set(h1, 'Color', col);

if plotarrows & ~barb,
% Make arrow heads and plot them
hu = [x+len.*cos(ang)-alpha*len.*sin(atan2(u,v)-0.5); ...
x+len.*cos(ang); ...
x+len.*cos(ang)-alpha*len.*cos(atan2(v,u)-0.5); ...
repmat(NaN,size(u))];

hv = [y+len.*sin(ang)-alpha*len.*cos(atan2(u,v)-0.5); ...
y+len.*sin(ang); ...
y+len.*sin(ang)-alpha*len.*sin(atan2(v,u)-0.5); ...
repmat(NaN,size(v))];

hold on
h2 = plot(hu(:),hv(:),[col ls]);
h3 = []; h4 = [];
elseif barb %  Redo this...
len2 = sqrt(u.^2 + v.^2);
%  First, determine how many barbs MAX will be on the flag
nbarb = max(fix(len2/50)+fix(mod(len2, 50)/10)+...
fix(mod(len2, 10)/5));
nbarb = max(nbarb, 6);

% Make barbs
flagd = 0.95*del/nbarb;  %  This controls the spacing between the
%  flags, on the barb
flagl = 0.35*del;     %  This controls the length of the flag

pt1 = [x-len.*cos(ang); y-len.*sin(ang)]';

hu = []; hv = [];
ind = fix(len2/50);
for i = find(ind);
for j = 1:ind(i);
hu = [hu ...
[pt1(i, 1); ...
pt1(i, 1)+(flagd/2).*cos(ang(i)) + ...
flagl*cos(ang(i)+pi/2); ...
pt1(i, 1)+(flagd).*cos(ang(i)); ...
pt1(i, 1)] ...
];
hv = [hv ...
[pt1(i, 2); ...
pt1(i, 2)+(flagd/2).*sin(ang(i)) + ...
flagl*sin(ang(i)+pi/2); ...
pt1(i, 2)+(flagd).*sin(ang(i));
pt1(i, 2)] ...
];
pt1(i,:) = pt1(i,:)+flagd*[cos(ang(i)) sin(ang(i))];
end
end
h2 = patch(hu, hv, col);
set(h2, 'FaceColor', col, 'EdgeColor', col);

%  Next, draw lines for 10 kt flags
hu = []; hv = [];
ind = fix(mod(len2, 50)/10);
for i = find(ind);
for j = 1:ind(i);
hu = [hu [pt1(i, 1)+(flagd/2).*cos(ang(i)); ...
pt1(i, 1)+(flagd/2).*cos(ang(i)) + ...
flagl*cos(ang(i)+pi/2); NaN] ];
hv = [hv [pt1(i, 2)+(flagd/2).*sin(ang(i)); ...
pt1(i, 2)+(flagd/2).*sin(ang(i)) + ...
flagl*sin(ang(i)+pi/2); NaN] ];
pt1(i,:) = pt1(i,:)+flagd*[cos(ang(i)) sin(ang(i))];
end
end
h3 = line(hu, hv);
set(h3, 'Color', col);

%  Next, draw lines for 10 kt flags
hu = []; hv = [];
ind = fix(mod(len2, 10)/5);
for i = find(ind);
for j = 1:ind(i);
hu = [hu [pt1(i, 1)+(flagd/2).*cos(ang(i)); ...
pt1(i, 1)+(flagd/2).*cos(ang(i)) + ...
0.5*flagl*cos(ang(i)+pi/2); NaN] ];
hv = [hv [pt1(i, 2)+(flagd/2).*sin(ang(i)); ...
pt1(i, 2)+(flagd/2).*sin(ang(i)) + ...
0.5*flagl*sin(ang(i)+pi/2); NaN] ];
pt1(i,:) = pt1(i,:)+flagd*[cos(ang(i)) sin(ang(i))];
end
end
h4 = line(hu, hv);
set(h4, 'Color', col);

end

if ~isempty(ms), % Plot marker on base
hu = x; hv = y;
hold on
h5 = plot(hu(:),hv(:),[col ms]);
if filled, set(h3,'markerfacecolor',get(h1,'color')); end
else
h5 = [];
end

if ~hold_state, hold off, view(2); set(ax,'NextPlot',next); end

if nargout>0, hh = [h1;h2;h3;h4;h5]; end
```