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 |
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; |
|
42 if (is_matrix (z)) |
2520
|
43 gset hidden3d; |
|
44 gset data style lines; |
|
45 gset surface; |
|
46 gset nocontour; |
|
47 gset noparametric; |
|
48 gset view 60, 30, 1, 1 |
1712
|
49 gsplot (z'); |
4
|
50 else |
|
51 error ("mesh: argument must be a matrix"); |
|
52 endif |
|
53 elseif (nargin == 3) |
|
54 if (is_vector (x) && is_vector (y) && is_matrix (z)) |
|
55 xlen = length (x); |
|
56 ylen = length (y); |
1712
|
57 if (xlen == columns (z) && ylen == rows (z)) |
|
58 if (rows (y) == 1) |
|
59 y = y'; |
4
|
60 endif |
1712
|
61 len = 3 * xlen; |
|
62 zz = zeros (ylen, len); |
4
|
63 k = 1; |
|
64 for i = 1:3:len |
1712
|
65 zz(:,i) = x(k) * ones (ylen, 1); |
|
66 zz(:,i+1) = y; |
4
|
67 zz(:,i+2) = z(:,k); |
|
68 k++; |
|
69 endfor |
3426
|
70 gset hidden3d; |
|
71 gset data style lines; |
2520
|
72 gset surface; |
|
73 gset nocontour; |
3426
|
74 gset parametric; |
2520
|
75 gset view 60, 30, 1, 1 |
3426
|
76 gsplot (zz); |
|
77 gset noparametric; |
4
|
78 else |
1712
|
79 msg = "mesh: rows (z) must be the same as length (x) and"; |
|
80 msg = sprintf ("%s\ncolumns (z) must be the same as length (y)", msg); |
904
|
81 error (msg); |
4
|
82 endif |
1712
|
83 elseif (is_matrix (x) && is_matrix (y) && is_matrix (z)) |
|
84 xlen = columns (z); |
|
85 ylen = rows (z); |
|
86 if (xlen == columns (x) && xlen == columns (y) && |
3426
|
87 ylen == rows (x) && ylen == rows(y)) |
1712
|
88 len = 3 * xlen; |
|
89 zz = zeros (ylen, len); |
|
90 k = 1; |
|
91 for i = 1:3:len |
|
92 zz(:,i) = x(:,k); |
|
93 zz(:,i+1) = y(:,k); |
|
94 zz(:,i+2) = z(:,k); |
|
95 k++; |
|
96 endfor |
3426
|
97 gset hidden3d; |
|
98 gset data style lines; |
2520
|
99 gset surface; |
|
100 gset nocontour; |
3426
|
101 gset parametric; |
2520
|
102 gset view 60, 30, 1, 1 |
3426
|
103 gsplot (zz); |
|
104 gset noparametric; |
1712
|
105 else |
|
106 error ("mesh: x, y, and z must have same dimensions"); |
|
107 endif |
4
|
108 else |
|
109 error ("mesh: x and y must be vectors and z must be a matrix"); |
2325
|
110 endif |
4
|
111 else |
904
|
112 usage ("mesh (z)"); |
4
|
113 endif |
|
114 |
|
115 endfunction |