]> Creatis software - CreaPhase.git/blob - octave_packages/m/plot/surf.m
update packages
[CreaPhase.git] / octave_packages / m / plot / surf.m
1 ## Copyright (C) 2007-2012 Kai Habel
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} {} surf (@var{x}, @var{y}, @var{z})
21 ## @deftypefnx {Function File} {} surf (@var{z})
22 ## @deftypefnx {Function File} {} surf (@dots{}, @var{c})
23 ## @deftypefnx {Function File} {} surf (@var{hax}, @dots{})
24 ## @deftypefnx {Function File} {@var{h} =} surf (@dots{})
25 ## Plot a surface given matrices @var{x}, and @var{y} from @code{meshgrid} and
26 ## a matrix @var{z} corresponding to the @var{x} and @var{y} coordinates of
27 ## the mesh.  If @var{x} and @var{y} are vectors, then a typical vertex
28 ## is (@var{x}(j), @var{y}(i), @var{z}(i,j)).  Thus, columns of @var{z}
29 ## correspond to different @var{x} values and rows of @var{z} correspond
30 ## to different @var{y} values.
31 ##
32 ## The color of the surface is derived from the @code{colormap} and
33 ## the value of @var{z}.  Optionally the color of the surface can be
34 ## specified independent of @var{z}, by adding a fourth matrix, @var{c}.
35 ##
36 ## The optional return value @var{h} is a graphics handle to the created
37 ## surface object.
38 ## @seealso{colormap, contour, meshgrid, mesh}
39 ## @end deftypefn
40
41 ## Author: Kai Habel <kai.habel@gmx.de>
42
43 function retval = surf (varargin)
44
45   [h, varargin] = __plt_get_axis_arg__ ("surf", varargin{:});
46
47   oldh = gca ();
48   unwind_protect
49     axes (h);
50     newplot ();
51     tmp = surface (varargin{:});
52
53     if (! ishold ())
54       set (h, "view", [-37.5, 30],
55            "xgrid", "on", "ygrid", "on", "zgrid", "on");
56     endif
57   unwind_protect_cleanup
58     axes (oldh);
59   end_unwind_protect
60
61   if (nargout > 0)
62     retval = tmp;
63   endif
64
65 endfunction
66
67
68 %!demo
69 %! clf
70 %! [~,~,Z] = peaks;
71 %! surf (Z);
72
73 %!demo
74 %! clf
75 %! [~,~,Z] = sombrero;
76 %! [Fx,Fy] = gradient (Z);
77 %! surf (Z, Fx+Fy);
78 %! shading interp;
79
80 %!demo
81 %! clf
82 %! [X,Y,Z] = sombrero;
83 %! [~,Fy] = gradient (Z);
84 %! surf (X, Y, Z, Fy);
85 %! shading interp;
86