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