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}) |
6154
|
22 ## Plot a mesh given matrices @var{x}, and @var{y} from @code{meshgrid} 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. |
5642
|
28 ## @seealso{meshgrid, contour} |
3368
|
29 ## @end deftypefn |
4
|
30 |
2314
|
31 ## Author: jwe |
|
32 |
2311
|
33 function mesh (x, y, z) |
4
|
34 |
|
35 if (nargin == 1) |
|
36 z = x; |
4030
|
37 if (ismatrix (z)) |
6154
|
38 [x, y] = meshgrid(0:columns(z)-1, 0:rows(z)-1); |
4
|
39 else |
|
40 error ("mesh: argument must be a matrix"); |
|
41 endif |
|
42 elseif (nargin == 3) |
4030
|
43 if (isvector (x) && isvector (y) && ismatrix (z)) |
6154
|
44 if (rows (z) == length (y) && columns (z) == length (x)) |
|
45 x = repmat(x(:)', length (y), 1); |
|
46 y = repmat(y(:), 1, length (x)); |
4
|
47 else |
3474
|
48 msg = "mesh: rows (z) must be the same as length (y) and"; |
|
49 msg = sprintf ("%s\ncolumns (z) must be the same as length (x)", msg); |
904
|
50 error (msg); |
4
|
51 endif |
4030
|
52 elseif (ismatrix (x) && ismatrix (y) && ismatrix (z)) |
6156
|
53 if (! (size_equal (x, y) && size_equal (x, z))) |
1712
|
54 error ("mesh: x, y, and z must have same dimensions"); |
|
55 endif |
4
|
56 else |
|
57 error ("mesh: x and y must be vectors and z must be a matrix"); |
2325
|
58 endif |
4
|
59 else |
6046
|
60 print_usage (); |
4
|
61 endif |
|
62 |
6154
|
63 ## Show the mesh. |
|
64 xlen = columns (z); |
|
65 ylen = rows (z); |
|
66 if (xlen == columns (x) && xlen == columns (y) |
|
67 && ylen == rows (x) && ylen == rows (y)) |
|
68 len = 3 * xlen; |
|
69 zz = zeros (ylen, len); |
|
70 k = 1; |
|
71 for i = 1:3:len |
|
72 zz(:,i) = x(:,k); |
|
73 zz(:,i+1) = y(:,k); |
|
74 zz(:,i+2) = z(:,k); |
|
75 k++; |
|
76 endfor |
|
77 __gnuplot_raw__ ("set hidden3d;\n"); |
|
78 __gnuplot_raw__ ("set data style lines;\n"); |
|
79 __gnuplot_raw__ ("set surface;\n"); |
|
80 __gnuplot_raw__ ("set nocontour;\n"); |
|
81 __gnuplot_raw__ ("set nologscale;\n"); |
|
82 __gnuplot_set__ parametric; |
|
83 __gnuplot_raw__ ("set view 60, 30, 1, 1;\n"); |
|
84 __gnuplot_raw__ ("set palette defined (0 \"dark-blue\", 1 \"blue\", 2 \"cyan\", 3 \"yellow\", 4 \"red\" , 5 \"dark-red\");\n"); |
|
85 __gnuplot_raw__ ("set nocolorbox;\n"); |
|
86 __plt3__ (zz, "", "", "", |
|
87 sprintf ("%s line palette", gnuplot_command_with ())); |
|
88 else |
|
89 error ("mesh: x, y, and z must have same dimensions"); |
|
90 endif |
|
91 |
4
|
92 endfunction |