2847
|
1 ## Copyright (C) 1996, 1997 John W. Eaton |
2313
|
2 ## |
|
3 ## This file is part of Octave. |
|
4 ## |
|
5 ## Octave is free software; you can redistribute it and/or modify it |
|
6 ## under the terms of the GNU General Public License as published by |
|
7 ## the Free Software Foundation; either version 2, or (at your option) |
|
8 ## any later version. |
|
9 ## |
|
10 ## Octave is distributed in the hope that it will be useful, but |
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 ## General Public License for more details. |
|
14 ## |
|
15 ## You should have received a copy of the GNU General Public License |
|
16 ## along with Octave; see the file COPYING. If not, write to the Free |
|
17 ## Software Foundation, 59 Temple Place - Suite 330, Boston, MA |
|
18 ## 02111-1307, USA. |
245
|
19 |
2311
|
20 ## usage: contour (z, n, x, y) |
|
21 ## |
|
22 ## See also: plot, semilogx, semilogy, loglog, polar, mesh, contour, |
2325
|
23 ## bar, stairs, gplot, gsplot, replot, xlabel, ylabel, title |
4
|
24 |
2314
|
25 ## Author: jwe |
|
26 |
2311
|
27 function contour (z, n, x, y) |
4
|
28 |
|
29 if (nargin == 1) |
|
30 n = 10; |
|
31 endif |
|
32 |
3063
|
33 ## XXX FIXME XXX -- these plot states should really just be set |
|
34 ## temporarily, probably inside an unwind_protect block, but there is |
|
35 ## no way to determine their current values. |
|
36 |
4
|
37 if (nargin == 1 || nargin == 2) |
|
38 if (is_matrix (z)) |
2520
|
39 gset nosurface; |
|
40 gset contour; |
|
41 gset cntrparam bspline; |
|
42 command = sprintf ("gset cntrparam levels %d", n); |
4
|
43 eval (command); |
2520
|
44 gset noparametric; |
2667
|
45 gset view 0, 0, 1, 1; |
4
|
46 gsplot z w l 1; |
|
47 else |
3063
|
48 error ("contour: argument must be a matrix"); |
4
|
49 endif |
|
50 elseif (nargin == 4) |
|
51 if (is_vector (x) && is_vector (y) && is_matrix (z)) |
|
52 xlen = length (x); |
|
53 ylen = length (y); |
|
54 if (xlen == rows (z) && ylen == columns (z)) |
|
55 if (rows (x) == 1) |
|
56 x = x'; |
|
57 endif |
|
58 len = 3 * ylen; |
2715
|
59 zz = zeros (xlen, len); |
4
|
60 k = 1; |
|
61 for i = 1:3:len |
|
62 zz(:,i) = x; |
|
63 zz(:,i+1) = y(k) * ones (xlen, 1); |
2715
|
64 zz(:,i+2) = z(k,:)'; |
4
|
65 k++; |
|
66 endfor |
2520
|
67 gset nosurface; |
|
68 gset contour; |
|
69 gset cntrparam bspline; |
2667
|
70 command = sprintf ("gset cntrparam levels %d", n); |
4
|
71 eval (command); |
2520
|
72 gset parametric; |
2667
|
73 gset view 0, 0, 1, 1; |
4
|
74 gsplot zz w l 1; |
|
75 else |
3063
|
76 msg = "contour: rows (z) must be the same as length (x) and"; |
904
|
77 msg = sprintf ("%s\ncolumns (z) must be the same as length (y)", msg); |
|
78 error (msg); |
4
|
79 endif |
|
80 else |
3063
|
81 error ("contour: x and y must be vectors and z must be a matrix"); |
2325
|
82 endif |
4
|
83 else |
3063
|
84 usage ("contour (z, levels, x, y)"); |
4
|
85 endif |
|
86 |
|
87 endfunction |