# quiverc

## PURPOSE

Modified version of Quiver to plots velocity vectors as arrows

## SYNOPSIS

function hh = quiverc(varargin)

## DESCRIPTION

     Modified version of Quiver to plots velocity vectors as arrows
     with components (u,v) at the points (x,y) using the current colormap

     Further edited by Frank L. Engel for use in VMT, allowing for custom
     scaling and colormap applications to be directed from the GUI 7/25/2013

     Bertrand Dano 3-3-03
     Copyright 1984-2002 The MathWorks, Inc.

## CROSS-REFERENCE INFORMATION

This function calls:

- cptcmap CPTCMAP Apply a .cpt file as colormap to an axis

This function is called by:

## SOURCE CODE

    0001  function hh = quiverc(varargin)
    0002 % Modified version of Quiver to plots velocity vectors as arrows
    0003 % with components (u,v) at the points (x,y) using the current colormap
    0004 %
    0005 % Further edited by Frank L. Engel for use in VMT, allowing for custom
    0006 % scaling and colormap applications to be directed from the GUI 7/25/2013
    0007 %
    0008 % Bertrand Dano 3-3-03
    0009 % Copyright 1984-2002 The MathWorks, Inc.
    0010
    0011 %QUIVERC Quiver color plot.
    0012 %   QUIVERC(X,Y,U,V) plots velocity vectors as arrows with components (u,v)
    0013 %   at the points (x,y).  The matrices X,Y,U,V must all be the same size
    0014 %   and contain corresponding position and velocity components (X and Y
    0015 %   can also be vectors to specify a uniform grid).  QUIVER automatically
    0016 %   scales the arrows to fit within the grid.
    0017 %
    0018 %   QUIVERC(U,V) plots velocity vectors at equally spaced points in
    0019 %   the x-y plane.
    0020 %
    0021 %   QUIVERC(U,V,S) or QUIVER(X,Y,U,V,S) automatically scales the
    0022 %   arrows to fit within the grid and then stretches them by S.  Use
    0023 %   S=0 to plot the arrows without the automatic scaling.
    0024 %
    0025 %   QUIVERC(...,LINESPEC) uses the plot linestyle specified for
    0026 %   the velocity vectors.  Any marker in LINESPEC is drawn at the base
    0027 %   instead of an arrow on the tip.  Use a marker of '.' to specify
    0028 %   no marker at all.  See PLOT for other possibilities.
    0029 %
    0030 %   QUIVERC(...,'filled') fills any markers specified.
    0031 %
    0032 %   H = QUIVERC(...) returns a vector of line handles.
    0033 %
    0034 %   Example:
    0035 %      [x,y] = meshgrid(-2:.2:2,-1:.15:1);
    0036 %      z = x .* exp(-x.^2 - y.^2); [px,py] = gradient(z,.2,.15);
    0037 %      contour(x,y,z), hold on
    0038 %      quiverc(x,y,px,py), hold off, axis image
    0039 %
    0040 %   See also FEATHER, QUIVER3, PLOT.
    0041 %   Clay M. Thompson 3-3-94
    0042 %   Copyright 1984-2002 The MathWorks, Inc.
    0043 %   $Revision: 5.21 $  $Date: 2002/06/05 20:05:16 $
    0044 %-------------------------------------------------------------
    0045
    0046
    0047 % set(gca, 'color', 'blue');
    0048 % Arrow head parameters
    0049 alpha = 0.33; % Size of arrow head relative to the length of the vector
    0050 beta = 0.23;  % Width of the base of the arrow head relative to the length
    0051 autoscale = 1; % Autoscale if ~= 0 then scale by this.
    0052 plotarrows = 1; % Plot arrows
    0053 sym = '';
    0054
    0055 nin = nargin;
    0056
    0057 % Check numeric input arguments
    0058 if nin<4, % quiver(u,v) or quiver(u,v,s)
    0059   [msg,x,y,u,v] = xyzchk(varargin{1:2});
    0060 else
    0061   [msg,x,y,u,v] = xyzchk(varargin{1:4});
    0062 end
    0063 if ~isempty(msg), error(msg); end
    0064
    0065 if nin==3 | nin==5, % quiver(u,v,s) or quiver(x,y,u,v,s)
    0066     autoscale   = varargin{nin};
    0067     minrng      = [];
    0068     maxrng      = [];
    0069     usecolormap = [];
    0070     cptfullfile = [];
    0071 elseif nin==9,
    0072     autoscale   = varargin{5};
    0073     minrng      = varargin{6};
    0074     maxrng      = varargin{7};
    0075     usecolormap = varargin{8};
    0076     cptfullfile = varargin{9};
    0077 end
    0078
    0079 % Setup a custom colormap
    0080 % quiverc fights for some reason if colormaps are longer than the standard
    0081 % 64 elements. Must first ensure that the custom CPT cmap is interpolated
    0082 % to 64 levels.
    0083 if ~isempty(cptfullfile) && strcmpi('Browse for more (cpt)...',usecolormap)
    0084     CC    = cptcmap(cptfullfile); % FEX in the utils folder
    0085 elseif ~isempty(usecolormap)
    0086     colormap(usecolormap)
    0087     CC = colormap;
    0088 else
    0089     colormap('jet')
    0090     CC = colormap;
    0091 end
    0092 c1    = CC(:,1); c2 = CC(:,2); c3 = CC(:,3);
    0093 CCx   = (1:size(CC,1))';
    0094 clevs = linspace(1,size(CC,1),64)'; clevs(end) = size(CC,1);
    0095 cc1   = interp1(CCx,c1,clevs);
    0096 cc2   = interp1(CCx,c2,clevs);
    0097 cc3   = interp1(CCx,c3,clevs);
    0098 colormap([cc1 cc2 cc3]);
    0099
    0100 filled = 0;
    0101 ls = '-';
    0102 ms = '';
    0103 col = '';
    0104 lw=1;
    0105
    0106 % Scalar expand u,v
    0107 if prod(size(u))==1, u = u(ones(size(x))); end
    0108 if prod(size(v))==1, v = v(ones(size(u))); end
    0109
    0110 if autoscale,
    0111   % Base autoscale value on average spacing in the x and y
    0112   % directions.  Estimate number of points in each direction as
    0113   % either the size of the input arrays or the effective square
    0114   % spacing if x and y are vectors.
    0115   if min(size(x))==1, n=sqrt(prod(size(x))); m=n; else [m,n]=size(x); end
    0116   delx = diff([min(x(:)) max(x(:))])/n;
    0117   dely = diff([min(y(:)) max(y(:))])/m;
    0118   len = sqrt((u.^2 + v.^2)/(delx.^2 + dely.^2));
    0119   autoscale = autoscale*0.9 / max(len(:));
    0120   u = u*autoscale; v = v*autoscale;
    0121 end
    0122
    0123 %----------------------------------------------
    0124 % Define colormap
    0125 vr=sqrt(u.^2+v.^2);
    0126 if ~isempty(minrng)
    0127     a = 1; b = 64;
    0128     vrn=round(...
    0129         (b-a)*(vr-minrng*autoscale)...
    0130         /(maxrng*autoscale-minrng*autoscale) + a...
    0131         );
    0132     vrn(vrn<1) = 1;
    0133     vrn(vrn>64) = 64;
    0134 else
    0135     vrn=round(vr/max(vr(:))*64);
    0136 end
    0137 CC=colormap;
    0138 ax = newplot;
    0139 next = lower(get(ax,'NextPlot'));
    0140 hold_state = ishold;
    0141
    0142 %----------------------------------------------
    0143 % Make velocity vectors and plot them
    0144
    0145 x = x(:).';y = y(:).';
    0146 u = u(:).';v = v(:).';
    0147 vrn=vrn(:).';
    0148 uu = [x;x+u;repmat(NaN,size(u))];
    0149 vv = [y;y+v;repmat(NaN,size(u))];
    0150 vrn1= [vrn;repmat(NaN,size(u));repmat(NaN,size(u))];
    0151
    0152 uui=uu(:);  vvi=vv(:);  vrn1=vrn1(:); imax=size(uui);
    0153 hold on
    0154
    0155  for i=  1:3:imax-1
    0156     ii=int8(round(vrn1(i)));
    0157     if ii==0; ii=1; end
    0158     c1= CC(ii,1);    c2= CC(ii,2);    c3= CC(ii,3);
    0159     plot(uui(i:i+1),vvi(i:i+1),'linewidth',lw,'color',[c1 c2 c3]);
    0160 end
    0161
    0162 %----------------------------------------------
    0163 % Make arrow heads and plot them
    0164 if plotarrows,
    0165
    0166   hu = [x+u-alpha*(u+beta*(v+eps));x+u; ...
    0167         x+u-alpha*(u-beta*(v+eps));repmat(NaN,size(u))];
    0168   hv = [y+v-alpha*(v-beta*(u+eps));y+v; ...
    0169         y+v-alpha*(v+beta*(u+eps));repmat(NaN,size(v))];
    0170   vrn2= [vrn;vrn;vrn;vrn];
    0171
    0172  uui=hu(:);  vvi=hv(:);  vrn2=vrn2(:); imax=size(uui);
    0173
    0174  for i=  1:imax-1
    0175     ii=int8(round(vrn2(i)));
    0176     if ii==0; ii=1; end
    0177     c1= CC(ii,1);    c2= CC(ii,2);    c3= CC(ii,3);
    0178     plot(uui(i:i+1),vvi(i:i+1),'linewidth',lw,'color',[c1 c2 c3]);
    0179  end
    0180
    0181 else
    0182   h2 = [];
    0183 end
    0184 %----------------------------------------------
    0185
    0186 if ~isempty(ms), % Plot marker on base
    0187   hu = x; hv = y;
    0188   hold on
    0189   h3 = plot(hu(:),hv(:),[col ms]);
    0190   if filled, set(h3,'markerfacecolor',get(h1,'color')); end
    0191 else
    0192   h3 = [];
    0193 end
    0194
    0195 if ~hold_state, hold off, view(2); set(ax,'NextPlot',next); end
    0196
    0197 if nargout>0, hh = [h1;h2;h3]; end
    0198 % set(gca, 'color', [0 0 0],'Xcolor','w','Ycolor','w');
    0199 % set(gcf, 'color', [0 0 0]);
    0200 % set(gcf, 'InvertHardCopy', 'off');