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 |
3368
|
20 ## -*- texinfo -*- |
|
21 ## @deftypefn {Function File} {} contour (@var{z}, @var{n}, @var{x}, @var{y}) |
|
22 ## Make a contour plot of the three-dimensional surface described by |
|
23 ## @var{z}. Someone needs to improve @code{gnuplot}'s contour routines |
|
24 ## before this will be very useful. |
|
25 ## @end deftypefn |
3407
|
26 ## @seealso{plot, semilogx, semilogy, loglog, polar, mesh, contour, |
3408
|
27 ## bar, stairs, gplot, gsplot, replot, xlabel, ylabel, and title} |
4
|
28 |
2314
|
29 ## Author: jwe |
|
30 |
2311
|
31 function contour (z, n, x, y) |
4
|
32 |
|
33 if (nargin == 1) |
|
34 n = 10; |
|
35 endif |
|
36 |
3063
|
37 ## XXX FIXME XXX -- these plot states should really just be set |
|
38 ## temporarily, probably inside an unwind_protect block, but there is |
|
39 ## no way to determine their current values. |
|
40 |
4
|
41 if (nargin == 1 || nargin == 2) |
|
42 if (is_matrix (z)) |
2520
|
43 gset nosurface; |
|
44 gset contour; |
|
45 gset cntrparam bspline; |
3131
|
46 if (is_scalar (n)) |
3426
|
47 command = sprintf ("gset cntrparam levels %d", n); |
3131
|
48 elseif (is_vector (n)) |
3426
|
49 tmp = sprintf ("%f", n(1)); |
|
50 for i = 2:length (n) |
|
51 tmp = sprintf ("%s, %f", tmp, n(i)); |
|
52 endfor |
|
53 command = sprintf ("gset cntrparam levels discrete %s", tmp); |
3131
|
54 endif |
4
|
55 eval (command); |
2520
|
56 gset noparametric; |
2667
|
57 gset view 0, 0, 1, 1; |
4
|
58 gsplot z w l 1; |
|
59 else |
3063
|
60 error ("contour: argument must be a matrix"); |
4
|
61 endif |
|
62 elseif (nargin == 4) |
|
63 if (is_vector (x) && is_vector (y) && is_matrix (z)) |
|
64 xlen = length (x); |
|
65 ylen = length (y); |
|
66 if (xlen == rows (z) && ylen == columns (z)) |
|
67 if (rows (x) == 1) |
|
68 x = x'; |
|
69 endif |
|
70 len = 3 * ylen; |
2715
|
71 zz = zeros (xlen, len); |
4
|
72 k = 1; |
|
73 for i = 1:3:len |
|
74 zz(:,i) = x; |
|
75 zz(:,i+1) = y(k) * ones (xlen, 1); |
3136
|
76 zz(:,i+2) = z(:,k); |
4
|
77 k++; |
|
78 endfor |
2520
|
79 gset nosurface; |
|
80 gset contour; |
|
81 gset cntrparam bspline; |
3426
|
82 if (is_scalar (n)) |
3131
|
83 command = sprintf ("gset cntrparam levels %d", n); |
3426
|
84 elseif (is_vector (n)) |
|
85 tmp = sprintf ("%f", n(1)); |
|
86 for i = 2:length (n) |
|
87 tmp = sprintf ("%s, %f", tmp, n(i)); |
|
88 endfor |
|
89 command = sprintf ("gset cntrparam levels discrete %s", tmp); |
|
90 endif |
4
|
91 eval (command); |
3426
|
92 gset parametric; |
2667
|
93 gset view 0, 0, 1, 1; |
3426
|
94 gsplot zz w l 1; |
4
|
95 else |
3063
|
96 msg = "contour: rows (z) must be the same as length (x) and"; |
904
|
97 msg = sprintf ("%s\ncolumns (z) must be the same as length (y)", msg); |
|
98 error (msg); |
4
|
99 endif |
|
100 else |
3063
|
101 error ("contour: x and y must be vectors and z must be a matrix"); |
2325
|
102 endif |
4
|
103 else |
3063
|
104 usage ("contour (z, levels, x, y)"); |
4
|
105 endif |
|
106 |
|
107 endfunction |