comparison scripts/plot/mesh.m @ 1712:26a5b528968c

[project @ 1996-01-08 02:15:53 by jwe]
author jwe
date Mon, 08 Jan 1996 02:15:53 +0000
parents b1b68110d125
children 5d29638dd524
comparison
equal deleted inserted replaced
1711:4d552a89ceaa 1712:26a5b528968c
12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 # for more details. 13 # for more details.
14 # 14 #
15 # You should have received a copy of the GNU General Public License 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 16 # along with Octave; see the file COPYING. If not, write to the Free
17 # Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 # Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18 18
19 function mesh (x, y, z) 19 function mesh (x, y, z)
20 20
21 # usage: mesh (x, y, z) 21 # usage: mesh (x, y, z)
22 # 22 #
23 # See also: plot, semilogx, semilogy, loglog, polar, meshdom, contour, 23 # Surface plot. If x, y, and z are matrices with the same dimensions,
24 # bar, stairs, gplot, gsplot, replot, xlabel, ylabel, title 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
25 31
26 if (nargin == 1) 32 if (nargin == 1)
27 z = x; 33 z = x;
28 if (is_matrix (z)) 34 if (is_matrix (z))
29 set hidden3d; 35 set hidden3d;
30 set data style lines; 36 set data style lines;
31 set surface; 37 set surface;
32 set nocontour; 38 set nocontour;
33 set noparametric; 39 set noparametric;
34 set view 60, 30, 1, 1; 40 set view 60, 30, 1, 1
35 gsplot (z); 41 gsplot (z');
36 else 42 else
37 error ("mesh: argument must be a matrix"); 43 error ("mesh: argument must be a matrix");
38 endif 44 endif
39 elseif (nargin == 3) 45 elseif (nargin == 3)
40 if (is_vector (x) && is_vector (y) && is_matrix (z)) 46 if (is_vector (x) && is_vector (y) && is_matrix (z))
41 xlen = length (x); 47 xlen = length (x);
42 ylen = length (y); 48 ylen = length (y);
43 if (ylen == rows (z) && xlen == columns (z)) 49 if (xlen == columns (z) && ylen == rows (z))
44 if (rows (x) == 1) 50 if (rows (y) == 1)
45 x = x'; 51 y = y';
46 endif 52 endif
47 len = 3 * ylen; 53 len = 3 * xlen;
48 zz = zeros (xlen, ylen); 54 zz = zeros (ylen, len);
49 k = 1; 55 k = 1;
50 for i = 1:3:len 56 for i = 1:3:len
51 zz(:,i) = x; 57 zz(:,i) = x(k) * ones (ylen, 1);
52 zz(:,i+1) = y(k) * ones (xlen, 1); 58 zz(:,i+1) = y;
53 zz(:,i+2) = z(:,k); 59 zz(:,i+2) = z(:,k);
54 k++; 60 k++;
55 endfor 61 endfor
56 set hidden3d; 62 set hidden3d;
57 set data style lines; 63 set data style lines;
58 set surface; 64 set surface;
59 set nocontour; 65 set nocontour;
60 set parametric; 66 set parametric;
61 set view 60, 30, 1, 1; 67 set view 60, 30, 1, 1
62 gsplot (zz); 68 gsplot (zz);
63 else 69 else
64 msg = "mesh: rows (z) must be the same as length (y) and"; 70 msg = "mesh: rows (z) must be the same as length (x) and";
65 msg = sprintf ("%s\ncolumns (z) must be the same as length (x)", msg); 71 msg = sprintf ("%s\ncolumns (z) must be the same as length (y)", msg);
66 error (msg); 72 error (msg);
73 endif
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");
67 endif 97 endif
68 else 98 else
69 error ("mesh: x and y must be vectors and z must be a matrix"); 99 error ("mesh: x and y must be vectors and z must be a matrix");
70 endif 100 endif
71 else 101 else