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} {} mesh (@var{x}, @var{y}, @var{z}) |
|
22 ## Plot a mesh given matrices @code{x}, and @var{y} from @code{meshdom} and |
|
23 ## a matrix @var{z} corresponding to the @var{x} and @var{y} coordinates of |
|
24 ## the mesh. If @var{x} and @var{y} are vectors, then a typical vertex |
|
25 ## is (@var{x}(j), @var{y}(i), @var{z}(i,j)). Thus, columns of @var{z} |
|
26 ## correspond to different @var{x} values and rows of @var{z} correspond |
|
27 ## to different @var{y} values. |
|
28 ## @end deftypefn |
|
29 |
2325
|
30 ## See also: plot, semilogx, semilogy, loglog, polar, meshgrid, meshdom, |
|
31 ## contour, bar, stairs, gplot, gsplot, replot, xlabel, ylabel, title |
4
|
32 |
2314
|
33 ## Author: jwe |
|
34 |
2311
|
35 function mesh (x, y, z) |
4
|
36 |
3063
|
37 ## XXX FIXME XXX -- the plot states should really just be set |
|
38 ## temporarily, probably inside an unwind_protect block, but there is |
|
39 ## no way to determine their current values. |
|
40 |
4
|
41 if (nargin == 1) |
|
42 z = x; |
|
43 if (is_matrix (z)) |
2520
|
44 gset hidden3d; |
|
45 gset data style lines; |
|
46 gset surface; |
|
47 gset nocontour; |
|
48 gset noparametric; |
|
49 gset view 60, 30, 1, 1 |
1712
|
50 gsplot (z'); |
4
|
51 else |
|
52 error ("mesh: argument must be a matrix"); |
|
53 endif |
|
54 elseif (nargin == 3) |
|
55 if (is_vector (x) && is_vector (y) && is_matrix (z)) |
|
56 xlen = length (x); |
|
57 ylen = length (y); |
1712
|
58 if (xlen == columns (z) && ylen == rows (z)) |
|
59 if (rows (y) == 1) |
|
60 y = y'; |
4
|
61 endif |
1712
|
62 len = 3 * xlen; |
|
63 zz = zeros (ylen, len); |
4
|
64 k = 1; |
|
65 for i = 1:3:len |
1712
|
66 zz(:,i) = x(k) * ones (ylen, 1); |
|
67 zz(:,i+1) = y; |
4
|
68 zz(:,i+2) = z(:,k); |
|
69 k++; |
|
70 endfor |
2520
|
71 gset hidden3d; |
|
72 gset data style lines; |
|
73 gset surface; |
|
74 gset nocontour; |
|
75 gset parametric; |
|
76 gset view 60, 30, 1, 1 |
4
|
77 gsplot (zz); |
3063
|
78 gset noparametric; |
4
|
79 else |
1712
|
80 msg = "mesh: rows (z) must be the same as length (x) and"; |
|
81 msg = sprintf ("%s\ncolumns (z) must be the same as length (y)", msg); |
904
|
82 error (msg); |
4
|
83 endif |
1712
|
84 elseif (is_matrix (x) && is_matrix (y) && is_matrix (z)) |
|
85 xlen = columns (z); |
|
86 ylen = rows (z); |
|
87 if (xlen == columns (x) && xlen == columns (y) && |
|
88 ylen == rows (x) && ylen == rows(y)) |
|
89 len = 3 * xlen; |
|
90 zz = zeros (ylen, len); |
|
91 k = 1; |
|
92 for i = 1:3:len |
|
93 zz(:,i) = x(:,k); |
|
94 zz(:,i+1) = y(:,k); |
|
95 zz(:,i+2) = z(:,k); |
|
96 k++; |
|
97 endfor |
2520
|
98 gset hidden3d; |
|
99 gset data style lines; |
|
100 gset surface; |
|
101 gset nocontour; |
|
102 gset parametric; |
|
103 gset view 60, 30, 1, 1 |
1712
|
104 gsplot (zz); |
3063
|
105 gset noparametric; |
1712
|
106 else |
|
107 error ("mesh: x, y, and z must have same dimensions"); |
|
108 endif |
4
|
109 else |
|
110 error ("mesh: x and y must be vectors and z must be a matrix"); |
2325
|
111 endif |
4
|
112 else |
904
|
113 usage ("mesh (z)"); |
4
|
114 endif |
|
115 |
|
116 endfunction |