]> Creatis software - CreaPhase.git/blob - octave_packages/m/plot/meshz.m
update packages
[CreaPhase.git] / octave_packages / m / plot / meshz.m
1 ## Copyright (C) 2007-2012 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   [h, varargin, nargin] = __plt_get_axis_arg__ ("meshz", varargin{:});
33
34   ioff = nargin + 1;
35   for i = 1:nargin
36     if (ischar (varargin{i}))
37       ioff = i;
38       break;
39     endif
40   endfor
41
42   ## Bundle C matrix back into varargin
43   if (ioff == 3 || ioff == 5)
44     ioff --;
45   endif
46
47   if (ioff == 2)
48     z = varargin{1};
49     [m, n] = size (z);
50     x = 1:n;
51     y = (1:m).';
52   else
53     x = varargin{1};
54     y = varargin{2};
55     z = varargin{3};
56   endif
57
58
59   if (isvector (x) && isvector (y))
60     x = [x(1), x(:).', x(end)];
61     y = [y(1); y(:); y(end)];
62   else
63     x = [x(1, 1), x(1, :), x(1, end);
64          x(:, 1), x, x(:, end);
65          x(end, 1), x(end, :), x(end, end)];
66     y = [y(1, 1), y(1, :), y(1, end);
67          y(:, 1), y, y(:, end);
68          y(end, 1), y(end, :), y(end, end)];
69   endif
70
71   zref = min(z(isfinite(z)));
72   z = [zref .* ones(1, size(z, 2) + 2);
73        zref .* ones(size(z, 1), 1), z, zref .* ones(size(z, 1), 1);
74        zref.* ones(1, size(z, 2) + 2)];
75
76   oldh = gca ();
77   unwind_protect
78     axes (h);
79     tmp = mesh (x, y, z, varargin{ioff:end});
80   unwind_protect_cleanup
81     axes (oldh);
82   end_unwind_protect
83
84   if (nargout > 0)
85     retval = tmp;
86   endif
87
88 endfunction