Mercurial > hg > octave-nkf
comparison scripts/plot/mesh.m @ 6257:44c91c5dfe1d
[project @ 2007-01-30 19:16:52 by jwe]
author | jwe |
---|---|
date | Tue, 30 Jan 2007 19:16:55 +0000 |
parents | 2de853a110df |
children | 334499d75c5c |
comparison
equal
deleted
inserted
replaced
6256:83949ae13b2c | 6257:44c91c5dfe1d |
---|---|
28 ## @seealso{meshgrid, contour} | 28 ## @seealso{meshgrid, contour} |
29 ## @end deftypefn | 29 ## @end deftypefn |
30 | 30 |
31 ## Author: jwe | 31 ## Author: jwe |
32 | 32 |
33 function mesh (x, y, z) | 33 function h = mesh (x, y, z) |
34 | |
35 __plot_globals__; | |
36 | |
37 cf = __current_figure__; | |
38 mxi = __multiplot_xi__(cf); | |
39 myi = __multiplot_yi__(cf); | |
40 | 34 |
41 if (nargin == 1) | 35 if (nargin == 1) |
42 z = x; | 36 z = x; |
43 if (ismatrix (z)) | 37 if (ismatrix (z)) |
44 [x, y] = meshgrid(0:columns(z)-1, 0:rows(z)-1); | 38 [nr, nc] = size (z); |
39 x = 1:nc; | |
40 y = (1:nr)'; | |
45 else | 41 else |
46 error ("mesh: argument must be a matrix"); | 42 error ("mesh: argument must be a matrix"); |
47 endif | 43 endif |
48 elseif (nargin == 3) | 44 elseif (nargin == 3) |
49 if (isvector (x) && isvector (y) && ismatrix (z)) | 45 if (isvector (x) && isvector (y) && ismatrix (z)) |
50 if (rows (z) == length (y) && columns (z) == length (x)) | 46 if (rows (z) == length (y) && columns (z) == length (x)) |
51 x = repmat(x(:)', rows (z), 1); | 47 x = x(:)'; |
52 y = repmat(y(:), 1, columns (z)); | 48 y = y(:); |
53 else | 49 else |
54 msg = "mesh: rows (z) must be the same as length (y) and"; | 50 msg = "mesh: rows (z) must be the same as length (y) and"; |
55 msg = sprintf ("%s\ncolumns (z) must be the same as length (x)", msg); | 51 msg = sprintf ("%s\ncolumns (z) must be the same as length (x)", msg); |
56 error (msg); | 52 error (msg); |
57 endif | 53 endif |
64 endif | 60 endif |
65 else | 61 else |
66 print_usage (); | 62 print_usage (); |
67 endif | 63 endif |
68 | 64 |
69 ## Show the mesh. | 65 ## make a default line object, and make it the current axes for the |
70 xlen = columns (z); | 66 ## current figure. |
71 ylen = rows (z); | 67 ca = gca (); |
72 if (xlen == columns (x) && xlen == columns (y) | 68 |
73 && ylen == rows (x) && ylen == rows (y)) | 69 s = __uiobject_surface_ctor__ (ca); |
74 len = 3 * xlen; | 70 |
75 zz = zeros (ylen, len); | 71 s.xdata = x; |
76 k = 1; | 72 s.ydata = y; |
77 for i = 1:3:len | 73 s.zdata = z; |
78 zz(:,i) = x(:,k); | 74 |
79 zz(:,i+1) = y(:,k); | 75 set (ca, "view", [-37.5, 30]); |
80 zz(:,i+2) = z(:,k); | 76 |
81 k++; | 77 tmp = __uiobject_make_handle__ (s); |
82 endfor | 78 |
83 __gnuplot_raw__ ("set hidden3d;\n"); | 79 __uiobject_adopt__ (ca, tmp); |
84 __gnuplot_raw__ ("set data style lines;\n"); | 80 |
85 __gnuplot_raw__ ("set surface;\n"); | 81 if (nargout > 0) |
86 __gnuplot_raw__ ("set nocontour;\n"); | 82 h = tmp; |
87 __gnuplot_raw__ ("set nologscale;\n"); | |
88 __gnuplot_raw__ ("set view 60, 30, 1, 1;\n"); | |
89 __gnuplot_raw__ ("set palette defined (0 \"dark-blue\", 1 \"blue\", 2 \"cyan\", 3 \"yellow\", 4 \"red\" , 5 \"dark-red\");\n"); | |
90 __gnuplot_raw__ ("set nocolorbox;\n"); | |
91 __plt3__ (zz, true, "", "", "", | |
92 sprintf ("%s line palette", gnuplot_command_with ())); | |
93 else | |
94 error ("mesh: x, y, and z must have same dimensions"); | |
95 endif | 83 endif |
96 | 84 |
97 endfunction | 85 endfunction |