2313
|
1 ## Copyright (C) 1996 John W. Eaton |
|
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, |
|
23 ## bar, stairs, gplot, gsplot, replot, xlabel, ylabel, title |
4
|
24 |
2311
|
25 function contour (z, n, x, y) |
4
|
26 |
|
27 |
|
28 if (nargin == 1) |
|
29 n = 10; |
|
30 endif |
|
31 |
|
32 if (nargin == 1 || nargin == 2) |
|
33 if (is_matrix (z)) |
|
34 set nosurface; |
|
35 set contour; |
1518
|
36 set cntrparam bspline; |
4
|
37 command = sprintf ("set cntrparam levels %d", n); |
|
38 eval (command); |
|
39 set noparametric; |
1518
|
40 set view 0, 0, 1.9, 1; |
4
|
41 gsplot z w l 1; |
|
42 else |
|
43 error ("mesh: argument must be a matrix"); |
|
44 endif |
|
45 elseif (nargin == 4) |
|
46 if (is_vector (x) && is_vector (y) && is_matrix (z)) |
|
47 xlen = length (x); |
|
48 ylen = length (y); |
|
49 if (xlen == rows (z) && ylen == columns (z)) |
|
50 if (rows (x) == 1) |
|
51 x = x'; |
|
52 endif |
|
53 len = 3 * ylen; |
|
54 zz = zeros (xlen, ylen); |
|
55 k = 1; |
|
56 for i = 1:3:len |
|
57 zz(:,i) = x; |
|
58 zz(:,i+1) = y(k) * ones (xlen, 1); |
|
59 zz(:,i+2) = z(:,k); |
|
60 k++; |
|
61 endfor |
1518
|
62 set nosurface; |
|
63 set contour; |
|
64 set cntrparam bspline; |
4
|
65 command = sprintf ("set cntrparam levels %d", n); |
|
66 eval (command); |
|
67 set parametric; |
1518
|
68 set view 0, 0, 1.9, 1; |
4
|
69 gsplot zz w l 1; |
|
70 else |
904
|
71 msg = "mesh: rows (z) must be the same as length (x) and"; |
|
72 msg = sprintf ("%s\ncolumns (z) must be the same as length (y)", msg); |
|
73 error (msg); |
4
|
74 endif |
|
75 else |
|
76 error ("mesh: x and y must be vectors and z must be a matrix"); |
|
77 endif |
|
78 else |
904
|
79 usage ("mesh (z, levels, x, y)"); |
4
|
80 endif |
|
81 |
|
82 endfunction |