1014
|
1 # Copyright (C) 1993, 1994, 1995 John W. Eaton |
245
|
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 the |
|
7 # Free Software Foundation; either version 2, or (at your option) any |
|
8 # later version. |
|
9 # |
|
10 # Octave is distributed in the hope that it will be useful, but WITHOUT |
|
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
13 # 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 |
1712
|
17 # Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
245
|
18 |
4
|
19 function mesh (x, y, z) |
|
20 |
|
21 # usage: mesh (x, y, z) |
|
22 # |
1712
|
23 # Surface plot. If x, y, and z are matrices with the same dimensions, |
|
24 # then corresponding elements represent vertices of the plot. If x and |
|
25 # y are vectors, then a typical vertex is (x(j), y(i), z(i,j)). Thus, |
|
26 # columns of z correspond to different x values and rows of z correspond |
|
27 # to different y values. |
|
28 # |
|
29 # See also: plot, semilogx, semilogy, loglog, polar, meshgrid, meshdom, |
|
30 # contour, bar, stairs, gplot, gsplot, replot, xlabel, ylabel, title |
4
|
31 |
|
32 if (nargin == 1) |
|
33 z = x; |
|
34 if (is_matrix (z)) |
|
35 set hidden3d; |
|
36 set data style lines; |
|
37 set surface; |
|
38 set nocontour; |
|
39 set noparametric; |
1712
|
40 set view 60, 30, 1, 1 |
|
41 gsplot (z'); |
4
|
42 else |
|
43 error ("mesh: argument must be a matrix"); |
|
44 endif |
|
45 elseif (nargin == 3) |
|
46 if (is_vector (x) && is_vector (y) && is_matrix (z)) |
|
47 xlen = length (x); |
|
48 ylen = length (y); |
1712
|
49 if (xlen == columns (z) && ylen == rows (z)) |
|
50 if (rows (y) == 1) |
|
51 y = y'; |
4
|
52 endif |
1712
|
53 len = 3 * xlen; |
|
54 zz = zeros (ylen, len); |
4
|
55 k = 1; |
|
56 for i = 1:3:len |
1712
|
57 zz(:,i) = x(k) * ones (ylen, 1); |
|
58 zz(:,i+1) = y; |
4
|
59 zz(:,i+2) = z(:,k); |
|
60 k++; |
|
61 endfor |
|
62 set hidden3d; |
|
63 set data style lines; |
|
64 set surface; |
|
65 set nocontour; |
|
66 set parametric; |
1712
|
67 set view 60, 30, 1, 1 |
4
|
68 gsplot (zz); |
|
69 else |
1712
|
70 msg = "mesh: rows (z) must be the same as length (x) and"; |
|
71 msg = sprintf ("%s\ncolumns (z) must be the same as length (y)", msg); |
904
|
72 error (msg); |
4
|
73 endif |
1712
|
74 elseif (is_matrix (x) && is_matrix (y) && is_matrix (z)) |
|
75 xlen = columns (z); |
|
76 ylen = rows (z); |
|
77 if (xlen == columns (x) && xlen == columns (y) && |
|
78 ylen == rows (x) && ylen == rows(y)) |
|
79 len = 3 * xlen; |
|
80 zz = zeros (ylen, len); |
|
81 k = 1; |
|
82 for i = 1:3:len |
|
83 zz(:,i) = x(:,k); |
|
84 zz(:,i+1) = y(:,k); |
|
85 zz(:,i+2) = z(:,k); |
|
86 k++; |
|
87 endfor |
|
88 set hidden3d; |
|
89 set data style lines; |
|
90 set surface; |
|
91 set nocontour; |
|
92 set parametric; |
|
93 set view 60, 30, 1, 1 |
|
94 gsplot (zz); |
|
95 else |
|
96 error ("mesh: x, y, and z must have same dimensions"); |
|
97 endif |
4
|
98 else |
|
99 error ("mesh: x and y must be vectors and z must be a matrix"); |
|
100 endif |
|
101 else |
904
|
102 usage ("mesh (z)"); |
4
|
103 endif |
|
104 |
|
105 endfunction |