Warning, /verification/lab_sea/matlab/myquiver.m is written in an unsupported language. File is not indexed.
view on githubraw file Latest commit add29e06 on 2018-01-31 20:35:05 UTC
baa476eeba Dimi*0001 function hh = myquiver(arg1,arg2,arg3,arg4,arg5,arg6)
0002 %MYQUIVER Quiver (or velocity) plot.
0003 % MYQUIVER(X,Y,U,V) plots the velocity vectors with components
0004 % (u,v) at the points (x,y). The matrices X,Y,U,V must all be
0005 % the same size and contain the cooresponding position and
0006 % velocity components (X and Y can also be vectors to specify a
0007 % uniform grid). MYQUIVER automatically scales the velocity
0008 % vectors to fit within the grid.
0009 %
0010 % MYQUIVER(U,V) plots the velocity vectors at equally spaced
0011 % points in the x-y plane.
0012 %
0013 % MYQUIVER(X,Y,S) or MYQUIVER(X,Y,U,V,S,...) automatically scales
0014 % the velocity vectors to fit within the grid and then multiplies
0015 % them by S. Use S=0 to plot the velocity vectors without the
0016 % automatic scaling.
0017 %
0018 % MYQUIVER(...,STYLE) uses the plot linestyle specified by the string
0019 % STYLE for the velocity vectors. See PLOT for other linestyles.
0020 %
0021 % H = MYQUIVER(...) returns a vector of line handles.
0022 %
0023 % Example:
0024 % [x,y] = meshgrid(-2:.2:2,-1:.15:1);
0025 % z = x .* exp(-x.^2 - y.^2); [px,py] = gradient(z,.2,.15);
0026 % contour(x,y,z), hold on
0027 % myquiver(x,y,px,py), hold off, axis image
0028 %
0029 % See also: FEATHER, PLOT, QUIVER
0030
0031 % Clay M. Thompson 3-3-94
0032 % Copyright (c) 1994 by The MathWorks, Inc.
0033
0034 % modified D Menemenlis 28 mar 95
0035 % modified from QUIVER for more consistent scaling
0036 % search for "modified" in text for details
0037
0038 error(nargchk(2,6,nargin));
0039
0040 % Arrow head parameters
0041 alpha = 0.33; % Size of arrow head relative to the length of the vector
0042 beta = 0.33; % Width of the base of the arrow head relative to the length
0043 autoscale = 1; % Autoscale if ~= 0 then scale by this.
0044
0045 % Check numeric input arguments
0046 if nargin<4
0047 [msg,x,y,u,v] = xyzchk(arg1,arg2);
0048 elseif nargin==4
0049 if isstr(arg4)
0050 [msg,x,y,u,v] = xyzchk(arg1,arg2);
0051 else
0052 [msg,x,y,u,v] = xyzchk(arg1,arg2,arg3,arg4);
0053 end
0054 else
0055 [msg,x,y,u,v] = xyzchk(arg1,arg2,arg3,arg4);
0056 end
0057 if ~isempty(msg), error(msg); end
0058
0059 if nargin==2, % myquiver(u,v)
0060 lo = get(gca,'LineStyleOrder'); sym = lo(1,:);
0061 elseif nargin==3, % myquiver(u,v,s) or myquiver(u,v,'style')
0062 if isstr(arg3),
0063 sym = arg3;
0064 else
0065 autoscale = arg3;
0066 lo = get(gca,'LineStyleOrder'); sym = lo(1,:);
0067 end
0068 elseif nargin==4, % myquiver(x,y,u,v) or myquiver(x,y,s,'style')
0069 if isstr(arg4),
0070 autoscale = arg3;
0071 sym = arg4;
0072 else
0073 lo = get(gca,'LineStyleOrder'); sym = lo(1,:);
0074 end
0075 elseif nargin==5, % myquiver(x,y,u,v,s) or myquiver(x,y,u,v,'style')
0076 if isstr(arg5),
0077 sym = arg5;
0078 else
0079 autoscale = arg5;
0080 lo = get(gca,'LineStyleOrder'); sym = lo(1,:);
0081 end
0082 elseif nargin==6, % myquiver(x,y,u,v,s,style)
0083 autoscale = arg5;
0084 sym = arg6;
0085 end
0086
0087 if autoscale,
0088 % Base autoscale value on average spacing in the x and y
0089 % directions. Estimate number of points in each direction as
0090 % either the size of the input arrays or the effective square
0091 % spacing if x and y are vectors.
0092 if min(size(x))==1, n=sqrt(prod(size(x))); m=n; else [m,n]=size(x); end
0093
0094 % modified D Menemenlis 28 mar 95
0095 % replaced "n" and "m" by "(n-1)" and "(m-1)" for more consistent scaling as
0096 % size of domain is increased
0097 delx = diff([min(x(find(~isnan(x)))) max(x(find(~isnan(x))))])/(n-1);
0098 dely = diff([min(y(find(~isnan(y)))) max(y(find(~isnan(y))))])/(m-1);
0099
0100 len = sqrt((u/delx).^2 + (v/dely).^2);
0101 autoscale = autoscale*0.9 / max(len(find(~isnan(len))));
0102 u = u*autoscale; v = v*autoscale;
0103 end
0104
0105 ax = newplot;
0106 next = lower(get(ax,'NextPlot'));
0107 hold_state = ishold;
0108
0109 % Make velocity vectors
0110 x = x(:).'; y = y(:).';
0111 u = u(:).'; v = v(:).';
0112
0113 % modified D Menemenlis 28 mar 95
0114 % added "+0*u" and "+0*v" to remove dots on plot for nans
0115
0116 uu = [x+0*u;x+u;NaN*ones(size(u))];
0117 vv = [y+0*v;y+v;NaN*ones(size(u))];
0118
0119 h = plot(uu(:),vv(:),sym);
0120
0121 % Make arrow heads and plot them
0122 hu = [x+u-alpha*(u+beta*(v+eps));x+u; ...
0123 x+u-alpha*(u-beta*(v+eps));NaN*ones(size(u))];
0124 hv = [y+v-alpha*(v-beta*(u+eps));y+v; ...
0125 y+v-alpha*(v+beta*(u+eps));NaN*ones(size(v))];
0126 hold on
0127 h = [h;plot(hu(:),hv(:),sym)];
0128
0129 if ~hold_state, hold off, view(2); set(ax,'NextPlot',next); end
0130
0131 if nargout>0, hh = h; end