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