0
|
1 ## Copyright (C) 1996, 1997 John W. Eaton |
|
2 ## |
|
3 ## This program is free software; you can redistribute it and/or modify |
|
4 ## it under the terms of the GNU General Public License as published by |
|
5 ## the Free Software Foundation; either version 2, or (at your option) |
|
6 ## any later version. |
|
7 ## |
|
8 ## This program is distributed in the hope that it will be useful, but |
|
9 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
11 ## General Public License for more details. |
|
12 ## |
|
13 ## You should have received a copy of the GNU General Public License |
|
14 ## along with this program; see the file COPYING. If not, write to the |
|
15 ## Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA |
|
16 ## 02111-1307, USA. |
|
17 |
|
18 ## -*- texinfo -*- |
|
19 ## @deftypefn {Function File} {} meshc (@var{x}, @var{y}, @var{z}) |
|
20 ## Plot a mesh given matrices @var{x}, and @var{y} from @code{meshdom} and |
|
21 ## a matrix @var{z} corresponding to the @var{x} and @var{y} coordinates of |
|
22 ## the mesh. If @var{x} and @var{y} are vectors, then a typical vertex |
|
23 ## is (@var{x}(j), @var{y}(i), @var{z}(i,j)). Thus, columns of @var{z} |
|
24 ## correspond to different @var{x} values and rows of @var{z} correspond |
|
25 ## to different @var{y} values. |
|
26 ## @end deftypefn |
|
27 ## @seealso{plot, semilogx, semilogy, loglog, polar, meshgrid, meshdom, |
|
28 ## contour, bar, stairs, gplot, gsplot, replot, xlabel, ylabel, and title} |
|
29 |
|
30 ## Author: jwe |
|
31 ## Modified: 2000-11-17 Paul Kienzle <kienzle.powernet.co.uk> |
|
32 ## copied from Octave 2.1.31 mesh.m, with contours turned on |
|
33 ## if added to octave, make __mesh__.m which takes the usual paramters |
|
34 ## in addition to 'surface' and 'contour' so that this code gets reused. |
|
35 |
|
36 function meshc (x, y, z) |
|
37 |
|
38 ## XXX FIXME XXX -- the 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 |
|
42 if (nargin == 1) |
|
43 z = x; |
|
44 if (is_matrix (z)) |
|
45 gset hidden3d; |
|
46 gset data style lines; |
|
47 gset surface; |
|
48 gset contour; |
|
49 gset noparametric; |
|
50 gset view 60, 30, 1, 1 |
|
51 gsplot (z'); |
|
52 else |
|
53 error ("mesh: argument must be a matrix"); |
|
54 endif |
|
55 elseif (nargin == 3) |
|
56 if (is_vector (x) && is_vector (y) && is_matrix (z)) |
|
57 xlen = length (x); |
|
58 ylen = length (y); |
|
59 if (xlen == columns (z) && ylen == rows (z)) |
|
60 if (rows (y) == 1) |
|
61 y = y'; |
|
62 endif |
|
63 len = 3 * xlen; |
|
64 zz = zeros (ylen, len); |
|
65 k = 1; |
|
66 for i = 1:3:len |
|
67 zz(:,i) = x(k) * ones (ylen, 1); |
|
68 zz(:,i+1) = y; |
|
69 zz(:,i+2) = z(:,k); |
|
70 k++; |
|
71 endfor |
|
72 gset hidden3d; |
|
73 gset data style lines; |
|
74 gset surface; |
|
75 gset contour; |
|
76 gset parametric; |
|
77 gset view 60, 30, 1, 1 |
|
78 gsplot (zz); |
|
79 gset noparametric; |
|
80 else |
|
81 msg = "mesh: rows (z) must be the same as length (y) and"; |
|
82 msg = sprintf ("%s\ncolumns (z) must be the same as length (x)", msg); |
|
83 error (msg); |
|
84 endif |
|
85 elseif (is_matrix (x) && is_matrix (y) && is_matrix (z)) |
|
86 xlen = columns (z); |
|
87 ylen = rows (z); |
|
88 if (xlen == columns (x) && xlen == columns (y) && |
|
89 ylen == rows (x) && ylen == rows(y)) |
|
90 len = 3 * xlen; |
|
91 zz = zeros (ylen, len); |
|
92 k = 1; |
|
93 for i = 1:3:len |
|
94 zz(:,i) = x(:,k); |
|
95 zz(:,i+1) = y(:,k); |
|
96 zz(:,i+2) = z(:,k); |
|
97 k++; |
|
98 endfor |
|
99 gset hidden3d; |
|
100 gset data style lines; |
|
101 gset surface; |
|
102 gset contour; |
|
103 gset parametric; |
|
104 gset view 60, 30, 1, 1 |
|
105 gsplot (zz); |
|
106 gset noparametric; |
|
107 else |
|
108 error ("mesh: x, y, and z must have same dimensions"); |
|
109 endif |
|
110 else |
|
111 error ("mesh: x and y must be vectors and z must be a matrix"); |
|
112 endif |
|
113 else |
|
114 usage ("mesh (z)"); |
|
115 endif |
|
116 |
|
117 endfunction |