Documentation of quiver_scale

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

Function Synopsis

hh = quiver_scale(varargin)

Help text

QUIVER_SCALE Quiver plot.
   QUIVER_SCALE(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_SCALE automatically scales the arrows to fit within the grid.

   QUIVER_SCALE(U,V) plots velocity vectors at equally spaced points in
   the x-y plane.

   QUIVER_SCALE(U,V,S) or QUIVER_SCALE(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_SCALE(U,V,S) with S < 0, automatically scales the arrows so
   that arrows of magnitude (or wind speed) abs(s) are assigned to the
   reference length.

   QUIVER_SCALE(...,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_SCALE(...,'filled') fills any markers specified.

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

      [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_scale

function hh = quiver_scale(varargin)

%   Clay M. Thompson 3-3-94
%   Copyright 1984-2001 The MathWorks, Inc. 
%   $Revision: 5.20 $  $Date: 2001/04/15 12:03:54 $
%   Modified by Dan Vimont, July 17, 2002
%   Changes include autoscale < 0 option, and redoing the arrowhead so
%   that it doesn't get all distorted.

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

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

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;
    [l,c,m,msg] = colstyle(vv);
    if ~isempty(msg), 
      error(sprintf('Unknown option "%s".',vv));
    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;


% Check numeric input arguments
if nin<4, % quiver(u,v) or quiver(u,v,s)
  [msg,x,y,u,v] = xyzchk(varargin{1:2});
  [msg,x,y,u,v] = xyzchk(varargin{1:4});
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};

% 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 > 0,
  % 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 = delx.^2 + dely.^2;
  if del>0
    len = sqrt((u.^2 + v.^2)/del);
    maxlen = max(len(:));
    maxlen = 0;
  if maxlen>0
    autoscale = autoscale*0.9 / maxlen;
    autoscale = autoscale*0.9;
  u = u*autoscale; v = v*autoscale;
elseif autoscale < 0,
  %  Base autoscale on a specified magnitude of the given vector.
  u = -1*u./autoscale; v = -1*v./autoscale;

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

% Make velocity vectors
x = x(:).'; y = y(:).';
u = u(:).'; v = v(:).';
uu = [x;x+u;repmat(NaN,size(u))];
vv = [y;y+v;repmat(NaN,size(u))];

h1 = plot(uu(:),vv(:),[col ls]);

if plotarrows,
  % Make arrow heads and plot them

  len = sqrt(u.^2 + v.^2);
  %orig  hu = [x+u-alpha*(u+beta*(v+eps));x+u; ...
  %orig        x+u-alpha*(u-beta*(v+eps));repmat(NaN,size(u))];

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

  %orig  hv = [y+v-alpha*(v-beta*(u+eps));y+v; ...
  %orig        y+v-alpha*(v+beta*(u+eps));repmat(NaN,size(v))];

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

  hold on
  h2 = plot(hu(:),hv(:),[col ls]);
  hold off
  h2 = [];

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

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

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