[37] | 1 | function hh = quiver(varargin) |
---|
| 2 | %QUIVER Quiver plot. |
---|
| 3 | % QUIVER(X,Y,U,V) plots velocity vectors as arrows with components (u,v) |
---|
| 4 | % at the points (x,y). The matrices X,Y,U,V must all be the same size |
---|
| 5 | % and contain corresponding position and velocity components (X and Y |
---|
| 6 | % can also be vectors to specify a uniform grid). QUIVER automatically |
---|
| 7 | % scales the arrows to fit within the grid. |
---|
| 8 | % |
---|
| 9 | % QUIVER(U,V) plots velocity vectors at equally spaced points in |
---|
| 10 | % the x-y plane. |
---|
| 11 | % |
---|
| 12 | % QUIVER(U,V,S) or QUIVER(X,Y,U,V,S) automatically scales the |
---|
| 13 | % arrows to fit within the grid and then stretches them by S. Use |
---|
| 14 | % S=0 to plot the arrows without the automatic scaling. |
---|
| 15 | % |
---|
| 16 | % QUIVER(...,LINESPEC) uses the plot linestyle specified for |
---|
| 17 | % the velocity vectors. Any marker in LINESPEC is drawn at the base |
---|
| 18 | % instead of an arrow on the tip. Use a marker of '.' to specify |
---|
| 19 | % no marker at all. See PLOT for other possibilities. |
---|
| 20 | % |
---|
| 21 | % QUIVER(...,'filled') fills any markers specified. |
---|
| 22 | % |
---|
| 23 | % H = QUIVER(...) returns a vector of line handles. |
---|
| 24 | % |
---|
| 25 | % Example: |
---|
| 26 | % [x,y] = meshgrid(-2:.2:2,-1:.15:1); |
---|
| 27 | % z = x .* exp(-x.^2 - y.^2); [px,py] = gradient(z,.2,.15); |
---|
| 28 | % contour(x,y,z), hold on |
---|
| 29 | % quiver(x,y,px,py), hold off, axis image |
---|
| 30 | % |
---|
| 31 | % See also FEATHER, QUIVER3, PLOT. |
---|
| 32 | |
---|
| 33 | % Clay M. Thompson 3-3-94 |
---|
| 34 | % Copyright 1984-2002 The MathWorks, Inc. |
---|
| 35 | % $Revision: 2.1 $ $Date: 2005/05/23 16:20:12 $ |
---|
| 36 | |
---|
| 37 | % Arrow head parameters |
---|
| 38 | alpha = 0.33; % Size of arrow head relative to the length of the vector |
---|
| 39 | beta = 0.33; % Width of the base of the arrow head relative to the length |
---|
| 40 | autoscale = 1; % Autoscale if ~= 0 then scale by this. |
---|
| 41 | plotarrows = 1; % Plot arrows |
---|
| 42 | sym = ''; |
---|
| 43 | |
---|
| 44 | filled = 0; |
---|
| 45 | ls = '-'; |
---|
| 46 | ms = ''; |
---|
| 47 | col = ''; |
---|
| 48 | |
---|
| 49 | nin = nargin; |
---|
| 50 | % Parse the string inputs |
---|
| 51 | while isstr(varargin{nin}), |
---|
| 52 | vv = varargin{nin}; |
---|
| 53 | if ~isempty(vv) & strcmp(lower(vv(1)),'f') |
---|
| 54 | filled = 1; |
---|
| 55 | nin = nin-1; |
---|
| 56 | else |
---|
| 57 | [l,c,m,msg] = colstyle(vv); |
---|
| 58 | if ~isempty(msg), |
---|
| 59 | error(sprintf('Unknown option "%s".',vv)); |
---|
| 60 | end |
---|
| 61 | if ~isempty(l), ls = l; end |
---|
| 62 | if ~isempty(c), col = c; end |
---|
| 63 | if ~isempty(m), ms = m; plotarrows = 0; end |
---|
| 64 | if isequal(m,'.'), ms = ''; end % Don't plot '.' |
---|
| 65 | nin = nin-1; |
---|
| 66 | end |
---|
| 67 | end |
---|
| 68 | |
---|
| 69 | error(nargchk(2,5,nin)); |
---|
| 70 | |
---|
| 71 | % Check numeric input arguments |
---|
| 72 | if nin<4, % quiver(u,v) or quiver(u,v,s) |
---|
| 73 | [msg,x,y,u,v] = xyzchk(varargin{1:2}); |
---|
| 74 | else |
---|
| 75 | [msg,x,y,u,v] = xyzchk(varargin{1:4}); |
---|
| 76 | end |
---|
| 77 | if ~isempty(msg), error(msg); end |
---|
| 78 | |
---|
| 79 | if nin==3 | nin==5, % quiver(u,v,s) or quiver(x,y,u,v,s) |
---|
| 80 | autoscale = varargin{nin}; |
---|
| 81 | end |
---|
| 82 | |
---|
| 83 | % Scalar expand u,v |
---|
| 84 | if prod(size(u))==1, u = u(ones(size(x))); end |
---|
| 85 | if prod(size(v))==1, v = v(ones(size(u))); end |
---|
| 86 | |
---|
| 87 | if autoscale, |
---|
| 88 | % Base autoscale value on average spacing in the x and y |
---|
| 89 | % directions. Estimate number of points in each direction as |
---|
| 90 | % either the size of the input arrays or the effective square |
---|
| 91 | % spacing if x and y are vectors. |
---|
| 92 | if min(size(x))==1, n=sqrt(prod(size(x))); m=n; else [m,n]=size(x); end |
---|
| 93 | delx = diff([min(x(:)) max(x(:))])/n; |
---|
| 94 | dely = diff([min(y(:)) max(y(:))])/m; |
---|
| 95 | del = delx.^2 + dely.^2; |
---|
| 96 | if del>0 |
---|
| 97 | len = sqrt((u.^2 + v.^2)/del); |
---|
| 98 | maxlen = max(len(:)); |
---|
| 99 | else |
---|
| 100 | maxlen = 0; |
---|
| 101 | end |
---|
| 102 | |
---|
| 103 | if maxlen>0 |
---|
| 104 | autoscale = autoscale*0.9 / maxlen; |
---|
| 105 | else |
---|
| 106 | autoscale = autoscale*0.9; |
---|
| 107 | end |
---|
| 108 | u = u*autoscale; v = v*autoscale; |
---|
| 109 | end |
---|
| 110 | |
---|
| 111 | ax = newplot; |
---|
| 112 | next = lower(get(ax,'NextPlot')); |
---|
| 113 | hold_state = ishold; |
---|
| 114 | |
---|
| 115 | % Make velocity vectors |
---|
| 116 | x = x(:).'; y = y(:).'; |
---|
| 117 | u = u(:).'; v = v(:).'; |
---|
| 118 | uu = [x;x+u;repmat(NaN,size(u))]; |
---|
| 119 | vv = [y;y+v;repmat(NaN,size(u))]; |
---|
| 120 | |
---|
| 121 | h1 = plot(uu(:),vv(:),[col ls]); |
---|
| 122 | |
---|
| 123 | if plotarrows, |
---|
| 124 | % Make arrow heads and plot them |
---|
| 125 | hu = [x+u-alpha*(u+beta*(v+eps));x+u; ... |
---|
| 126 | x+u-alpha*(u-beta*(v+eps));repmat(NaN,size(u))]; |
---|
| 127 | hv = [y+v-alpha*(v-beta*(u+eps));y+v; ... |
---|
| 128 | y+v-alpha*(v+beta*(u+eps));repmat(NaN,size(v))]; |
---|
| 129 | hold on |
---|
| 130 | h2 = plot(hu(:),hv(:),[col ls]); |
---|
| 131 | else |
---|
| 132 | h2 = []; |
---|
| 133 | end |
---|
| 134 | |
---|
| 135 | if ~isempty(ms), % Plot marker on base |
---|
| 136 | hu = x; hv = y; |
---|
| 137 | hold on |
---|
| 138 | h3 = plot(hu(:),hv(:),[col ms]); |
---|
| 139 | if filled, set(h3,'markerfacecolor',get(h1,'color')); end |
---|
| 140 | else |
---|
| 141 | h3 = []; |
---|
| 142 | end |
---|
| 143 | |
---|
| 144 | if ~hold_state, hold off, view(2); set(ax,'NextPlot',next); end |
---|
| 145 | |
---|
| 146 | if nargout>0, hh = [h1;h2;h3]; end |
---|