]> Creatis software - CreaPhase.git/blob - octave_packages/m/plot/surfc.m
update packages
[CreaPhase.git] / octave_packages / m / plot / surfc.m
1 ## Copyright (C) 1996-2012 John W. Eaton
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} {} surfc (@var{x}, @var{y}, @var{z})
21 ## Plot a surface and contour 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, surf, contour}
28 ## @end deftypefn
29
30 function h = surfc (varargin)
31
32   newplot ();
33
34   tmp = surface (varargin{:});
35
36   ax = get (tmp, "parent");
37
38   set (tmp, "facecolor", "flat");
39
40   if (! ishold ())
41     set (ax, "view", [-37.5, 30],
42          "xgrid", "on", "ygrid", "on", "zgrid", "on");
43   endif
44
45   drawnow ();
46   zmin = get (ax, "zlim")(1);
47
48   # don't pass axis handle and/or string arguments to __contour__()
49   stop_idx = nargin;
50   for i = 2 : nargin
51     if (ischar (varargin{i}))
52       stop_idx = i - 1;
53       break;
54     endif
55   endfor
56
57   start_idx = 1;
58   if (ishandle (varargin{1}))
59     start_idx = 2;
60   endif
61
62   if (stop_idx - start_idx == 1 || stop_idx - start_idx == 3)
63     #don't pass a color matrix c to __contour__
64     stop_idx -= 1;
65   endif
66
67   [c, tmp2] = __contour__ (ax, zmin, varargin{start_idx:stop_idx});
68
69   tmp = [tmp; tmp2];
70
71   if (nargout > 0)
72     h = tmp;
73   endif
74
75 endfunction
76
77 %!demo
78 %! clf
79 %! [~,~,Z]=peaks;
80 %! surfc(Z);
81
82 %!demo
83 %! clf
84 %! [~,~,Z]=sombrero;
85 %! [Fx,Fy] = gradient(Z);
86 %! surfc(Z,Fx+Fy);
87 %! shading interp;
88
89 %!demo
90 %! clf
91 %! [X,Y,Z]=sombrero;
92 %! [~,Fy] = gradient(Z);
93 %! surfc(X,Y,Z,Fy);
94 %! shading interp;