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