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; |
3131
|
42 if (is_scalar (n)) |
|
43 command = sprintf ("gset cntrparam levels %d", n); |
|
44 elseif (is_vector (n)) |
|
45 tmp = sprintf ("%f", n(1)); |
|
46 for i = 2:length (n) |
|
47 tmp = sprintf ("%s, %f", tmp, n(i)); |
|
48 endfor |
|
49 command = sprintf ("gset cntrparam levels discrete %s", tmp); |
|
50 endif |
4
|
51 eval (command); |
2520
|
52 gset noparametric; |
2667
|
53 gset view 0, 0, 1, 1; |
4
|
54 gsplot z w l 1; |
|
55 else |
3063
|
56 error ("contour: argument must be a matrix"); |
4
|
57 endif |
|
58 elseif (nargin == 4) |
|
59 if (is_vector (x) && is_vector (y) && is_matrix (z)) |
|
60 xlen = length (x); |
|
61 ylen = length (y); |
|
62 if (xlen == rows (z) && ylen == columns (z)) |
|
63 if (rows (x) == 1) |
|
64 x = x'; |
|
65 endif |
|
66 len = 3 * ylen; |
2715
|
67 zz = zeros (xlen, len); |
4
|
68 k = 1; |
|
69 for i = 1:3:len |
|
70 zz(:,i) = x; |
|
71 zz(:,i+1) = y(k) * ones (xlen, 1); |
3136
|
72 zz(:,i+2) = z(:,k); |
4
|
73 k++; |
|
74 endfor |
2520
|
75 gset nosurface; |
|
76 gset contour; |
|
77 gset cntrparam bspline; |
3131
|
78 if (is_scalar (n)) |
|
79 command = sprintf ("gset cntrparam levels %d", n); |
|
80 elseif (is_vector (n)) |
|
81 tmp = sprintf ("%f", n(1)); |
|
82 for i = 2:length (n) |
|
83 tmp = sprintf ("%s, %f", tmp, n(i)); |
|
84 endfor |
|
85 command = sprintf ("gset cntrparam levels discrete %s", tmp); |
|
86 endif |
4
|
87 eval (command); |
2520
|
88 gset parametric; |
2667
|
89 gset view 0, 0, 1, 1; |
4
|
90 gsplot zz w l 1; |
|
91 else |
3063
|
92 msg = "contour: rows (z) must be the same as length (x) and"; |
904
|
93 msg = sprintf ("%s\ncolumns (z) must be the same as length (y)", msg); |
|
94 error (msg); |
4
|
95 endif |
|
96 else |
3063
|
97 error ("contour: x and y must be vectors and z must be a matrix"); |
2325
|
98 endif |
4
|
99 else |
3063
|
100 usage ("contour (z, levels, x, y)"); |
4
|
101 endif |
|
102 |
|
103 endfunction |