function retval=vecplot(xin,yin,uin,vin,varargin) %VECPLOT draw vectors on the current axes % VECPLOT draws vectors on the current axes, given % vector origins (x,y) and vector magnitudes (u,v). % % VECPLOT scales the magnitude of % (u,v) by the magnitude of max(abs(u,v)) and then % forces a vector of magnitude sc to be 10% of the x data % range. By default, sc = 1., so that a 1 m/s vector will % be scaled to 10% of the x data range. If sc=.5, then % a vector magnitude of 50 cm/s will be scaled to 10% of the % x data range. Decreasing sc serves to make the vectors % appear larger. VECPLOT draws a vector scale according to % the user input (see below). % % INPUT: x,y - vector origins % u,v - vector amplitudes % 'help' - if the only argument to VECPLOT is 'help' % additional information on its usage is returned % to the screen. % % OUTPUT: h - vector of handles to the vector lines drawn, the % the scale vector text, and the scale vector handles. % Type >> vecplot('help') for details. % If the 'stick' method is used, then h is ordered like: % h(1) -> vector shaft object (Tag=vectors') % h(2) -> stick vector origin object (Tag=vecrots') % h(3) -> scale vector text object (Tag=scaletext') % h(4) -> scale vector shaft object (Tag=scalearrow') % h(5) -> scale vector origin object (Tag=scalearrow') % If the 'arrow' method is used, then h is ordered like: % h(1) -> vector object (Tag=vectors') % h(2) -> scale vector text object (Tag=scaletext') % h(3) -> scale vector object (Tag=scalearrow') % % PN/PV pairs accepted by VECPLOT: % ArrowAngle - angle (in degrees) that the arrow head wings % make with the shaft. Default=25 % DotColor - origin symbol color, for VecType=='stick'. Default='k'. % DotSize - origin symbol size, for VecType=='stick'. Default=10. % DotStyle - origin symbol, or VecType=='stick'. Default='.'. % MaxThresh - Maximum vector magnitude to plot. Default=Inf. % MinThresh - Minimum vector magnitude to plot. Default=0. % PctAxis - Percent of axis for scale length. Default=10. % ScaleFac - vector scaling factor. Default=1. % ScaleLabel - label for vector scale; 'no scale' prevents scale % from being drawn; Default='m/s'. % ScaleType - how to draw the vector scale, either 'fixed' or % 'floating'; Default='fixed'. % ScaleXor - scale x-origin; Default=[]. % ScaleYor - scale y-origin; Default=[]. % Stride - amount to stride over in drawing vectors. Default=1, % meaning no stride. % VecType - vector drawing method, either 'arrow' or 'stick'; % Default='arrow'. % % NOTES: VECPLOT requires atleast 2 coordinates and vectors. % % CALL: hv=vecplot(x,y,u,v,pn1,pv1,...); % % Written by : Brian O. Blanton % % DEFINE ERROR STRINGS err1=['Invalid number of input arguments to VECPLOT']; err2=['VECPLOT no longer can accept a fem_grid_struct.']; err3=['Lengths of x,y,u,v must be the same']; err4=['Length of (x,y) must equal length of (u,v).']; err5=['Alteast 3 arguments are required if first is a fem_grid_struct.']; err6=['Alteast 4 arguments are required if first two are x,y.']; err7=['Second optional argument (sclab) must be a string.']; err8=['Both x- and y-coords of vector scale must be specified.']; if nargin==0,disp('Call as: hv=vecplot(x,y,u,v,pn1,pv1,...)');return;end if nargin==1,vecplothelp(xin);return;end if nargin<4 error(err1) end if isstruct(xin) error(err2) end % Check lengths of x,y,u,v if length(uin)~=length(vin) | length(xin)~=length(yin) | length(xin)~=length(uin) error(err3) end % Default propertyname values MinThresh=0.; MaxThresh=Inf; ScaleLabel='m/s'; ScaleType='fixed'; Stride=1; VecType='arrow'; ScaleFac=1.; ScaleXor=[]; ScaleYor=[]; PctAxis=10; % Strip off propertyname/value pairs in varargin not related to % "line" object properties. k=1; while k1 if any([m n]==1) i=1:Stride:length(xin); else i=(1:Stride:m)'; % j=cumsum(Stride*m*ones(size(0:Stride:n-(Stride+1))))'; j=repmat(i,[1 length(1:Stride:n)]); ij=j+repmat((0:Stride:n-1)*n,[length(1:Stride:n) 1]); i=ij(:); end else i=1:Stride:length(xin); end x=xin(i); y=yin(i); u=uin(i); v=vin(i); %keyboard %FILTER DATA THROUGH VIEWING WINDOW % filt=find(x>=X1&x<=X2&y>=Y1&y<=Y2); x=x(filt); y=y(filt); u=u(filt); v=v(filt); % Delete any NaN's mag=sqrt(u.*u+v.*v); % Unit mag %mag=mag/max(mag); iding=find(isnan(mag)); % Further eliminate vectors whose magnitude is at or below MinThresh. %iding=[iding;find(mag<=MinThresh/100)]; iding=[iding;find(mag<=MinThresh)]; % Further eliminate vectors whose magnitude is at or above MaxThresh. %iding=[iding;find(mag>=MaxThresh)]; iding=[iding;find(mag>=MaxThresh)]; x(iding)=[]; y(iding)=[]; u(iding)=[]; v(iding)=[]; % SCALE BY ScaleFac IN U AND V % us=u/ScaleFac; vs=v/ScaleFac; % SCALE TO 10 PERCENT OF X RANGE % us=us*pct10; vs=vs*pct10; % SEND VECTORS TO DRAWVEC ROUTINE % switch VecType case 'arrow' %Strip out attributes not used in arrow mode. k=1; while k vector shaft object (Tag=vectors)\n')]; str=[str sprintf(' h(2) -> stick vector origin object (Tag=vecrots)\n')]; str=[str sprintf(' h(3) -> scale vector text object (Tag=scaletext)\n')]; str=[str sprintf(' h(4) -> scale vector shaft object (Tag=scalearrow)\n')]; str=[str sprintf(' h(5) -> scale vector origin object (Tag=scalearrow)\n')]; str=[str sprintf('\n If the ''arrow'' method is used, then h is ordered like:\n')]; str=[str sprintf(' h(1) -> vector object (Tag=vectors)\n')]; str=[str sprintf(' h(2) -> scale vector text object (Tag=scaletext)\n')]; str=[str sprintf(' h(3) -> scale vector object (Tag=scalearrow)\n')]; str=[str sprintf('\nPN/PV pairs accepted by VECPLOT:\n')]; str=[str sprintf(' ArrowAngle - angle (in degrees) that the arrow head wings\n')]; str=[str sprintf(' make with the shaft. Default=25.\n')]; str=[str sprintf(' DotColor - origin symbol color, for VecType==''stick''. Default=''k''\n')]; str=[str sprintf(' DotSize - origin symbol size, for VecType==''stick''. Default=10\n')]; str=[str sprintf(' DotStyle - origin symbol, or VecType==''stick''. Default=''.''\n')]; str=[str sprintf(' MaxThresh - Maximum vector magnitude to plot. Default=Inf.\n')]; str=[str sprintf(' MinThresh - Minimum vector magnitude to plot. Default=0.\n')]; str=[str sprintf(' ScaleFac - vector scaling factor. Default=1.\n')]; str=[str sprintf(' ScaleLabel - label for vector scale; ''no scale'' prevents scale\n')]; str=[str sprintf(' from being drawn; Default=''m/s''.\n')]; str=[str sprintf(' ScaleType - how to draw the vector scale, either ''fixed'' or\n')]; str=[str sprintf(' ''floating''; Default=''fixed''.\n')]; str=[str sprintf(' ScaleXor - scale x-origin; Default=[].\n')]; str=[str sprintf(' ScaleYor - scale y-origin; Default=[].\n')]; str=[str sprintf(' Stride - amount to stride over in drawing vectors. Default=1,\n')]; str=[str sprintf(' meaning no stride. Stride=2 skips every other point.\n')]; str=[str sprintf(' VecType - vector drawing method, either ''arrow'' or ''stick'';\n')]; str=[str sprintf(' Default=''arrow''.\n')]; title1='VECPLOT Additional Help'; otherwise error('invalid help string to VECPLOT') end if ~isempty(str) helpwin(str,title1); end % %LabSig Brian O. Blanton % Department of Marine Sciences % 12-7 Venable Hall % CB# 3300 % University of North Carolina % Chapel Hill, NC % 27599-3300 % % brian_blanton@unc.edu % % SUMMER 1998 %