7207
|
1 ## Copyright (C) 2007 David Bateman |
|
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 3 of the License, or (at |
|
8 ## your option) 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, see |
|
17 ## <http://www.gnu.org/licenses/>. |
|
18 |
|
19 ## -*- texinfo -*- |
|
20 ## @deftypefn {Function File} {} meshz (@var{x}, @var{y}, @var{z}) |
|
21 ## Plot a curtain mesh given matrices @var{x}, and @var{y} from |
|
22 ## @code{meshgrid} and a matrix @var{z} corresponding to the @var{x} and |
|
23 ## @var{y} coordinates of the mesh. If @var{x} and @var{y} are vectors, |
|
24 ## then a typical vertex is (@var{x}(j), @var{y}(i), @var{z}(i,j)). Thus, |
|
25 ## columns of @var{z} correspond to different @var{x} values and rows of |
|
26 ## @var{z} correspond to different @var{y} values. |
|
27 ## @seealso{meshgrid, mesh, contour} |
|
28 ## @end deftypefn |
|
29 |
|
30 function retval = meshz (varargin) |
|
31 |
|
32 if (isscalar (varargin{1}) && ishandle (varargin{1})) |
|
33 h = varargin {1}; |
|
34 if (! strcmp (get (h, "type"), "axes")) |
|
35 error ("meshz: expecting first argument to be an axes object"); |
|
36 endif |
|
37 oldh = gca (); |
|
38 unwind_protect |
|
39 axes (h); |
|
40 tmp = __meshz__ (varargin{2:end}); |
|
41 unwind_protect_cleanup |
|
42 axes (oldh); |
|
43 end_unwind_protect |
|
44 else |
|
45 tmp = __meshz__ (varargin{:}); |
|
46 endif |
|
47 |
|
48 if (nargout > 0) |
|
49 retval = tmp; |
|
50 endif |
|
51 |
|
52 endfunction |
|
53 |
|
54 function h = __meshz__ (varargin) |
|
55 |
|
56 ioff = nargin + 1; |
|
57 for i = 1 : nargin |
|
58 if (ischar (varargin {i})) |
|
59 ioff = i; |
|
60 break; |
|
61 endif |
|
62 endfor |
|
63 |
|
64 ## Bundle C matrix back into varargin |
|
65 if (ioff == 3 || ioff == 5) |
|
66 ioff --; |
|
67 endif |
|
68 |
|
69 if (ioff == 2) |
|
70 z = varargin {1}; |
|
71 [m, n] = size (z); |
|
72 x = 1 : n; |
|
73 y = (1 : m).'; |
|
74 else |
|
75 x = varargin {1}; |
|
76 y = varargin {2}; |
|
77 z = varargin {3}; |
|
78 endif |
|
79 |
|
80 |
|
81 if (isvector (x) && isvector (y)) |
|
82 x = [x(1), x(:).', x(end)]; |
|
83 y = [y(1); y(:); y(end)]; |
|
84 else |
|
85 x = [x(1, 1), x(1, :), x(1, end); |
|
86 x(:, 1), x, x(:, end); |
|
87 x(end, 1), x(end, :), x(end, end)]; |
|
88 y = [y(1, 1), y(1, :), y(1, end); |
|
89 y(:, 1), y, y(:, end); |
|
90 y(end, 1), y(end, :), y(end, end)]; |
|
91 endif |
|
92 |
|
93 zref = min(z(isfinite(z))); |
|
94 z = [zref .* ones(1, size(z, 2) + 2); |
|
95 zref .* ones(size(z, 1), 1), z, zref .* ones(size(z, 1), 1); |
|
96 zref.* ones(1, size(z, 2) + 2)]; |
|
97 |
|
98 h = mesh (x, y, z, varargin{ioff:end}); |
|
99 |
|
100 endfunction |