0
|
1 ## Copyright (C) 2000 John W. Eaton |
|
2 ## |
|
3 ## This program is free software; you can redistribute it and/or modify it |
|
4 ## under the terms of the GNU General Public License as published by |
|
5 ## the Free Software Foundation; either version 2, or (at your option) |
|
6 ## any later version. |
|
7 ## |
|
8 ## This program is distributed in the hope that it will be useful, but |
|
9 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
11 ## General Public License for more details. |
|
12 ## |
|
13 ## You should have received a copy of the GNU General Public License |
|
14 ## along with this program; see the file COPYING. If not, write to the Free |
|
15 ## Software Foundation, 59 Temple Place - Suite 330, Boston, MA |
|
16 ## 02111-1307, USA. |
|
17 |
|
18 ## usage: quiver (x, y, u, v) |
|
19 ## usage: quiver (u, v) |
|
20 ## |
|
21 ## Plot the (u,v) components of a vector field in a (x,y) meshgrid. |
|
22 ## |
|
23 ## You can try: |
|
24 ## |
|
25 ## a = b = 1:10; |
|
26 ## [x,y] = meshgrid(a,b); |
|
27 ## u = rand (10,10); |
|
28 ## v = rand (10,10); |
|
29 ## quiver(x,y,u,v) |
|
30 ## |
|
31 ## See also: plot, semilogx, semilogy, loglog, polar, mesh, contour, |
|
32 ## bar, stairs, gplot, gsplot, replot, xlabel, ylabel, title |
|
33 |
|
34 ## Author: Roberto A. F. Almeida (roberto@calvin.ocfis.furg.br) |
|
35 ## 2001-02-25 Paul Kienzle |
|
36 ## * change parameter order to correspond to matlab |
|
37 ## * allow vector x,y, defaulting to 1:n, 1:m for mxn u |
|
38 ## * vectorize |
|
39 |
|
40 ## TODO: use gnuplot 'vector' style instead of setting arrows one at a time |
|
41 function quiver (x, y, u, v) |
|
42 |
|
43 if (nargin != 2 && nargin != 4) |
|
44 usage ("quiver (x, y, u, v)"); |
|
45 endif |
|
46 |
|
47 if (nargin == 2) |
|
48 u = x; v = y; x = 1:columns(u); y= 1:rows(u); |
|
49 endif |
|
50 |
|
51 if (any(size(u)!=size(v))) |
|
52 error ("quiver: u, v must have the same shape."); |
|
53 endif |
|
54 |
|
55 if is_vector(x) && is_vector(y) |
|
56 [nr, nc] = size(u); |
|
57 if (length(x) != nc || length(y) != nr) |
|
58 error ("quiver: x, y vectors must have correct length"); |
|
59 endif |
|
60 [x,y] = meshgrid(x,y); |
|
61 endif |
|
62 |
|
63 if (any (size(x) != size(u) | size(y) != size(u))) |
|
64 error ("quiver: x, y must have the same shape as u, v"); |
|
65 endif |
|
66 |
|
67 |
|
68 ## Calculating the grid limits. |
|
69 |
|
70 minx = min (min (x)); |
|
71 maxx = max (max (x)); |
|
72 miny = min (min (y)); |
|
73 maxy = max (max (y)); |
|
74 |
|
75 max_arrow = max ( [max(max (u)) , max(max (v)) , ... |
|
76 abs(min (min (u))) , abs(min (min (v)))] ); |
|
77 border = max_arrow * 1.2; |
|
78 |
|
79 limits = [ minx - border, maxx + border, miny - border, maxy + border ]; |
|
80 |
|
81 axis (limits); |
|
82 |
|
83 |
|
84 ## Ok, now plot the arrows. |
|
85 |
|
86 gset noarrow; |
|
87 gplot 0 title ""; |
|
88 |
|
89 command = sprintf ("gset arrow from %f,%f to %f,%f\n", \ |
|
90 [ x(:)'; y(:)'; x(:)'+u(:)'; y(:)'+v(:)' ]); |
|
91 eval ( [ "if 1\n", command, "\nendif" ] ); |
|
92 |
|
93 replot; |
|
94 |
|
95 endfunction |