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 |
5307
|
17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
18 ## 02110-1301, 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 |
5053
|
29 ## |
5390
|
30 ## @seealso{meshgrid, contour} |
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)) |
5252
|
43 __gnuplot_raw__ ("set hidden3d;\n"); |
|
44 __gnuplot_raw__ ("set data style lines;\n"); |
|
45 __gnuplot_raw__ ("set surface;\n"); |
|
46 __gnuplot_raw__ ("set nocontour;\n"); |
5215
|
47 __gnuplot_set__ noparametric; |
5252
|
48 __gnuplot_raw__ ("set nologscale;\n"); |
|
49 __gnuplot_raw__ ("set view 60, 30, 1, ;\n"); |
5215
|
50 __gnuplot_splot__ (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 |
5252
|
71 __gnuplot_raw__ ("set hidden3d;\n"); |
|
72 __gnuplot_raw__ ("set data style lines;\n"); |
|
73 __gnuplot_raw__ ("set surface;\n"); |
|
74 __gnuplot_raw__ ("set nocontour;\n"); |
|
75 __gnuplot_raw__ ("set nologscale;\n"); |
5215
|
76 __gnuplot_set__ parametric; |
5252
|
77 __gnuplot_raw__ ("set view 60, 30, 1, 1;\n"); |
5474
|
78 __gnuplot_set__ palette defined ( 0 "dark-blue", 1 "blue", ... |
|
79 2 "cyan", 3 "yellow", 4 "red" , 5 "dark-red" ) |
|
80 __gnuplot_set__ nocolorbox |
|
81 __gnuplot_splot__ zz with line palette; |
5215
|
82 __gnuplot_set__ noparametric; |
4
|
83 else |
3474
|
84 msg = "mesh: rows (z) must be the same as length (y) and"; |
|
85 msg = sprintf ("%s\ncolumns (z) must be the same as length (x)", msg); |
904
|
86 error (msg); |
4
|
87 endif |
4030
|
88 elseif (ismatrix (x) && ismatrix (y) && ismatrix (z)) |
1712
|
89 xlen = columns (z); |
|
90 ylen = rows (z); |
|
91 if (xlen == columns (x) && xlen == columns (y) && |
3426
|
92 ylen == rows (x) && ylen == rows(y)) |
1712
|
93 len = 3 * xlen; |
|
94 zz = zeros (ylen, len); |
|
95 k = 1; |
|
96 for i = 1:3:len |
|
97 zz(:,i) = x(:,k); |
|
98 zz(:,i+1) = y(:,k); |
|
99 zz(:,i+2) = z(:,k); |
|
100 k++; |
|
101 endfor |
5252
|
102 __gnuplot_raw__ ("set hidden3d;\n") |
|
103 __gnuplot_raw__ ("set data style lines;\n"); |
|
104 __gnuplot_raw__ ("set surface;\n"); |
|
105 __gnuplot_raw__ ("set nocontour;\n"); |
|
106 __gnuplot_raw__ ("set nologscale;\n"); |
5215
|
107 __gnuplot_set__ parametric; |
5252
|
108 __gnuplot_raw__ ("set view 60, 30, 1, 1;\n"); |
5215
|
109 __gnuplot_splot__ (zz); |
|
110 __gnuplot_set__ noparametric; |
1712
|
111 else |
|
112 error ("mesh: x, y, and z must have same dimensions"); |
|
113 endif |
4
|
114 else |
|
115 error ("mesh: x and y must be vectors and z must be a matrix"); |
2325
|
116 endif |
4
|
117 else |
904
|
118 usage ("mesh (z)"); |
4
|
119 endif |
|
120 |
|
121 endfunction |