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