Mercurial > forge
comparison FIXES/contour.m @ 0:6b33357c7561 octave-forge
Initial revision
author | pkienzle |
---|---|
date | Wed, 10 Oct 2001 19:54:49 +0000 |
parents | |
children | 2ac2777b30bc |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:6b33357c7561 |
---|---|
1 ## Copyright (C) 1996, 1997 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. | |
19 | |
20 ## -*- texinfo -*- | |
21 ## @deftypefn {Function File} {} contour (@var{z}, @var{n}) | |
22 ## @deftypefnx {Function File} {} contour (@var{x}, @var{y}, @var{z}, @var{n}) | |
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 | |
27 ## @seealso{plot, semilogx, semilogy, loglog, polar, mesh, contour, | |
28 ## bar, stairs, gplot, gsplot, replot, xlabel, ylabel, and title} | |
29 | |
30 ## Author: jwe | |
31 ## Paul Kienzle <pkienzle@kienzle.powernet.co.uk> | |
32 ## matlab compatible interface | |
33 | |
34 function contour (x, y, z, n) | |
35 | |
36 ## XXX FIXME XXX -- these plot states should really just be set | |
37 ## temporarily, probably inside an unwind_protect block, but there is | |
38 ## no way to determine their current values. | |
39 | |
40 if (nargin == 1 || nargin == 2) | |
41 z = x; | |
42 if (nargin == 1) | |
43 n = 10; | |
44 else | |
45 n = y; | |
46 endif | |
47 if (is_matrix (z)) | |
48 gset nosurface; | |
49 gset contour; | |
50 gset cntrparam bspline; | |
51 if (is_scalar (n)) | |
52 command = sprintf ("gset cntrparam levels %d", n); | |
53 elseif (is_vector (n)) | |
54 tmp = sprintf ("%f", n(1)); | |
55 for i = 2:length (n) | |
56 tmp = sprintf ("%s, %f", tmp, n(i)); | |
57 endfor | |
58 command = sprintf ("gset cntrparam levels discrete %s", tmp); | |
59 endif | |
60 eval (command); | |
61 gset noparametric; | |
62 gset view 0, 0, 1, 1; | |
63 gsplot z w l 1; | |
64 else | |
65 error ("contour: argument must be a matrix"); | |
66 endif | |
67 elseif (nargin == 3 || nargin == 4) | |
68 if (nargin == 3) n = 9; endif | |
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; | |
77 zz = zeros (xlen, len); | |
78 k = 1; | |
79 for i = 1:3:len | |
80 zz(:,i) = x; | |
81 zz(:,i+1) = y(k) * ones (xlen, 1); | |
82 zz(:,i+2) = z(:,k); | |
83 k++; | |
84 endfor | |
85 gset nosurface; | |
86 gset contour; | |
87 gset cntrparam bspline; | |
88 if (is_scalar (n)) | |
89 command = sprintf ("gset cntrparam levels %d", n); | |
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 | |
97 eval (command); | |
98 gset parametric; | |
99 gset view 0, 0, 1, 1; | |
100 gsplot zz w l 1; | |
101 else | |
102 msg = "contour: rows (z) must be the same as length (x) and"; | |
103 msg = sprintf ("%s\ncolumns (z) must be the same as length (y)", msg); | |
104 error (msg); | |
105 endif | |
106 else | |
107 error ("contour: x and y must be vectors and z must be a matrix"); | |
108 endif | |
109 else | |
110 usage ("contour (z, levels, x, y)"); | |
111 endif | |
112 | |
113 endfunction |