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}) |
3600
|
22 ## Plot a mesh given matrices @var{x}, and @var{y} from @code{meshdom} and |
3368
|
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 |
3407
|
29 ## @seealso{plot, semilogx, semilogy, loglog, polar, meshgrid, meshdom, |
3408
|
30 ## contour, bar, stairs, gplot, gsplot, replot, xlabel, ylabel, and title} |
4
|
31 |
2314
|
32 ## Author: jwe |
|
33 |
2311
|
34 function mesh (x, y, z) |
4
|
35 |
3063
|
36 ## XXX FIXME XXX -- the 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 |
4
|
40 if (nargin == 1) |
|
41 z = x; |
4030
|
42 if (ismatrix (z)) |
2520
|
43 gset hidden3d; |
|
44 gset data style lines; |
|
45 gset surface; |
|
46 gset nocontour; |
|
47 gset noparametric; |
3717
|
48 gset nologscale; |
2520
|
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) |
4030
|
55 if (isvector (x) && isvector (y) && ismatrix (z)) |
4
|
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 |
3426
|
71 gset hidden3d; |
|
72 gset data style lines; |
2520
|
73 gset surface; |
|
74 gset nocontour; |
3717
|
75 gset nologscale; |
3426
|
76 gset parametric; |
2520
|
77 gset view 60, 30, 1, 1 |
3426
|
78 gsplot (zz); |
|
79 gset noparametric; |
4
|
80 else |
3474
|
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); |
904
|
83 error (msg); |
4
|
84 endif |
4030
|
85 elseif (ismatrix (x) && ismatrix (y) && ismatrix (z)) |
1712
|
86 xlen = columns (z); |
|
87 ylen = rows (z); |
|
88 if (xlen == columns (x) && xlen == columns (y) && |
3426
|
89 ylen == rows (x) && ylen == rows(y)) |
1712
|
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 |
3426
|
99 gset hidden3d; |
|
100 gset data style lines; |
2520
|
101 gset surface; |
|
102 gset nocontour; |
3717
|
103 gset nologscale; |
3426
|
104 gset parametric; |
2520
|
105 gset view 60, 30, 1, 1 |
3426
|
106 gsplot (zz); |
|
107 gset noparametric; |
1712
|
108 else |
|
109 error ("mesh: x, y, and z must have same dimensions"); |
|
110 endif |
4
|
111 else |
|
112 error ("mesh: x and y must be vectors and z must be a matrix"); |
2325
|
113 endif |
4
|
114 else |
904
|
115 usage ("mesh (z)"); |
4
|
116 endif |
|
117 |
|
118 endfunction |