904
|
1 # Copyright (C) 1993, 1994 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 |
|
17 # Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
|
18 |
4
|
19 function mesh (x, y, z) |
|
20 |
|
21 # usage: mesh (x, y, z) |
|
22 # |
|
23 # See also: plot, semilogx, semilogy, loglog, polar, meshdom, contour, |
|
24 # bar, stairs, gplot, gsplot, replot, xlabel, ylabel, title |
|
25 |
|
26 if (nargin == 1) |
|
27 z = x; |
|
28 if (is_matrix (z)) |
|
29 set hidden3d; |
|
30 set data style lines; |
|
31 set surface; |
|
32 set nocontour; |
|
33 set noparametric; |
|
34 set view 60, 30, 1, 1 |
|
35 gsplot (z); |
|
36 else |
|
37 error ("mesh: argument must be a matrix"); |
|
38 endif |
|
39 elseif (nargin == 3) |
|
40 if (is_vector (x) && is_vector (y) && is_matrix (z)) |
|
41 xlen = length (x); |
|
42 ylen = length (y); |
|
43 if (xlen == rows (z) && ylen == columns (z)) |
|
44 if (rows (x) == 1) |
|
45 x = x'; |
|
46 endif |
|
47 len = 3 * ylen; |
|
48 zz = zeros (xlen, ylen); |
|
49 k = 1; |
|
50 for i = 1:3:len |
|
51 zz(:,i) = x; |
|
52 zz(:,i+1) = y(k) * ones (xlen, 1); |
|
53 zz(:,i+2) = z(:,k); |
|
54 k++; |
|
55 endfor |
|
56 set hidden3d; |
|
57 set data style lines; |
|
58 set surface; |
|
59 set nocontour; |
|
60 set parametric; |
|
61 set view 60, 30, 1, 1 |
|
62 gsplot (zz); |
|
63 else |
904
|
64 msg = "mesh: rows (z) must be the same as length (x) and"; |
|
65 msg = sprintf ("%s\ncolumns (z) must be the same as length (y)", msg); |
|
66 error (msg); |
4
|
67 endif |
|
68 else |
|
69 error ("mesh: x and y must be vectors and z must be a matrix"); |
|
70 endif |
|
71 else |
904
|
72 usage ("mesh (z)"); |
4
|
73 endif |
|
74 |
|
75 endfunction |