annotate scripts/plot/surf.m @ 12812:4c93cc41da15 stable

codesprint: add demo for surf.m and surfc.m
author Kai Habel <kai.habel@gmx.de>
date Sat, 16 Jul 2011 20:56:20 +0200
parents d6619410e79c
children 5f0bb45e615c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11523
fd0a3ac60b0e update copyright notices
John W. Eaton <jwe@octave.org>
parents: 11101
diff changeset
1 ## Copyright (C) 2007-2011 Kai Habel
7109
5436efbf35e3 [project @ 2007-11-06 22:16:25 by jwe]
jwe
parents:
diff changeset
2 ##
5436efbf35e3 [project @ 2007-11-06 22:16:25 by jwe]
jwe
parents:
diff changeset
3 ## This file is part of Octave.
5436efbf35e3 [project @ 2007-11-06 22:16:25 by jwe]
jwe
parents:
diff changeset
4 ##
5436efbf35e3 [project @ 2007-11-06 22:16:25 by jwe]
jwe
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
5436efbf35e3 [project @ 2007-11-06 22:16:25 by jwe]
jwe
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by
5436efbf35e3 [project @ 2007-11-06 22:16:25 by jwe]
jwe
parents:
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
5436efbf35e3 [project @ 2007-11-06 22:16:25 by jwe]
jwe
parents:
diff changeset
8 ## your option) any later version.
5436efbf35e3 [project @ 2007-11-06 22:16:25 by jwe]
jwe
parents:
diff changeset
9 ##
5436efbf35e3 [project @ 2007-11-06 22:16:25 by jwe]
jwe
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
5436efbf35e3 [project @ 2007-11-06 22:16:25 by jwe]
jwe
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
5436efbf35e3 [project @ 2007-11-06 22:16:25 by jwe]
jwe
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5436efbf35e3 [project @ 2007-11-06 22:16:25 by jwe]
jwe
parents:
diff changeset
13 ## General Public License for more details.
5436efbf35e3 [project @ 2007-11-06 22:16:25 by jwe]
jwe
parents:
diff changeset
14 ##
5436efbf35e3 [project @ 2007-11-06 22:16:25 by jwe]
jwe
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
5436efbf35e3 [project @ 2007-11-06 22:16:25 by jwe]
jwe
parents:
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
5436efbf35e3 [project @ 2007-11-06 22:16:25 by jwe]
jwe
parents:
diff changeset
17 ## <http://www.gnu.org/licenses/>.
5436efbf35e3 [project @ 2007-11-06 22:16:25 by jwe]
jwe
parents:
diff changeset
18
5436efbf35e3 [project @ 2007-11-06 22:16:25 by jwe]
jwe
parents:
diff changeset
19 ## -*- texinfo -*-
11563
3c6e8aaa9555 Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
20 ## @deftypefn {Function File} {} surf (@var{x}, @var{y}, @var{z})
11101
1f9ab076f5f7 Include the 4 input (color) in the docstrings for mesh() and surf().
Ben Abbott <bpabbott@mac.com>
parents: 10549
diff changeset
21 ## @deftypefnx {Function File} {} surf (@var{z})
1f9ab076f5f7 Include the 4 input (color) in the docstrings for mesh() and surf().
Ben Abbott <bpabbott@mac.com>
parents: 10549
diff changeset
22 ## @deftypefnx {Function File} {} surf (@dots{}, @var{c})
1f9ab076f5f7 Include the 4 input (color) in the docstrings for mesh() and surf().
Ben Abbott <bpabbott@mac.com>
parents: 10549
diff changeset
23 ## @deftypefnx {Function File} {} surf (@var{hax}, @dots{})
11563
3c6e8aaa9555 Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
24 ## @deftypefnx {Function File} {@var{h} =} surf (@dots{})
7109
5436efbf35e3 [project @ 2007-11-06 22:16:25 by jwe]
jwe
parents:
diff changeset
25 ## Plot a surface given matrices @var{x}, and @var{y} from @code{meshgrid} and
5436efbf35e3 [project @ 2007-11-06 22:16:25 by jwe]
jwe
parents:
diff changeset
26 ## a matrix @var{z} corresponding to the @var{x} and @var{y} coordinates of
5436efbf35e3 [project @ 2007-11-06 22:16:25 by jwe]
jwe
parents:
diff changeset
27 ## the mesh. If @var{x} and @var{y} are vectors, then a typical vertex
5436efbf35e3 [project @ 2007-11-06 22:16:25 by jwe]
jwe
parents:
diff changeset
28 ## is (@var{x}(j), @var{y}(i), @var{z}(i,j)). Thus, columns of @var{z}
5436efbf35e3 [project @ 2007-11-06 22:16:25 by jwe]
jwe
parents:
diff changeset
29 ## correspond to different @var{x} values and rows of @var{z} correspond
5436efbf35e3 [project @ 2007-11-06 22:16:25 by jwe]
jwe
parents:
diff changeset
30 ## to different @var{y} values.
11101
1f9ab076f5f7 Include the 4 input (color) in the docstrings for mesh() and surf().
Ben Abbott <bpabbott@mac.com>
parents: 10549
diff changeset
31 ##
11575
d6619410e79c Spellcheck documentation before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents: 11563
diff changeset
32 ## The color of the surface is derived from the @code{colormap} and
11563
3c6e8aaa9555 Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
33 ## the value of @var{z}. Optionally the color of the surface can be
3c6e8aaa9555 Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
34 ## specified independent of @var{z}, by adding a fourth matrix, @var{c}.
11101
1f9ab076f5f7 Include the 4 input (color) in the docstrings for mesh() and surf().
Ben Abbott <bpabbott@mac.com>
parents: 10549
diff changeset
35 ## @seealso{colormap, contour, meshgrid, mesh}
7109
5436efbf35e3 [project @ 2007-11-06 22:16:25 by jwe]
jwe
parents:
diff changeset
36 ## @end deftypefn
5436efbf35e3 [project @ 2007-11-06 22:16:25 by jwe]
jwe
parents:
diff changeset
37
7110
0e63f1126f01 [project @ 2007-11-06 22:36:22 by jwe]
jwe
parents: 7109
diff changeset
38 ## Author: Kai Habel <kai.habel@gmx.de>
7109
5436efbf35e3 [project @ 2007-11-06 22:16:25 by jwe]
jwe
parents:
diff changeset
39
7216
5389a52df87b [project @ 2007-11-29 19:07:29 by jwe]
jwe
parents: 7215
diff changeset
40 function retval = surf (varargin)
7109
5436efbf35e3 [project @ 2007-11-06 22:16:25 by jwe]
jwe
parents:
diff changeset
41
7215
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7146
diff changeset
42 [h, varargin] = __plt_get_axis_arg__ ("surf", varargin{:});
7109
5436efbf35e3 [project @ 2007-11-06 22:16:25 by jwe]
jwe
parents:
diff changeset
43
7215
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7146
diff changeset
44 oldh = gca ();
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7146
diff changeset
45 unwind_protect
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7146
diff changeset
46 axes (h);
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7146
diff changeset
47 newplot ();
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7146
diff changeset
48 tmp = surface (varargin{:});
7110
0e63f1126f01 [project @ 2007-11-06 22:36:22 by jwe]
jwe
parents: 7109
diff changeset
49
7215
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7146
diff changeset
50 if (! ishold ())
7298
d42d8c43d3e7 [project @ 2007-12-11 21:49:31 by jwe]
jwe
parents: 7268
diff changeset
51 set (h, "view", [-37.5, 30],
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 7298
diff changeset
52 "xgrid", "on", "ygrid", "on", "zgrid", "on");
7215
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7146
diff changeset
53 endif
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7146
diff changeset
54 unwind_protect_cleanup
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7146
diff changeset
55 axes (oldh);
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7146
diff changeset
56 end_unwind_protect
7110
0e63f1126f01 [project @ 2007-11-06 22:36:22 by jwe]
jwe
parents: 7109
diff changeset
57
7109
5436efbf35e3 [project @ 2007-11-06 22:16:25 by jwe]
jwe
parents:
diff changeset
58 if (nargout > 0)
7216
5389a52df87b [project @ 2007-11-29 19:07:29 by jwe]
jwe
parents: 7215
diff changeset
59 retval = tmp;
7109
5436efbf35e3 [project @ 2007-11-06 22:16:25 by jwe]
jwe
parents:
diff changeset
60 endif
5436efbf35e3 [project @ 2007-11-06 22:16:25 by jwe]
jwe
parents:
diff changeset
61
5436efbf35e3 [project @ 2007-11-06 22:16:25 by jwe]
jwe
parents:
diff changeset
62 endfunction
12812
4c93cc41da15 codesprint: add demo for surf.m and surfc.m
Kai Habel <kai.habel@gmx.de>
parents: 11575
diff changeset
63
4c93cc41da15 codesprint: add demo for surf.m and surfc.m
Kai Habel <kai.habel@gmx.de>
parents: 11575
diff changeset
64 %!demo
4c93cc41da15 codesprint: add demo for surf.m and surfc.m
Kai Habel <kai.habel@gmx.de>
parents: 11575
diff changeset
65 %! clf
4c93cc41da15 codesprint: add demo for surf.m and surfc.m
Kai Habel <kai.habel@gmx.de>
parents: 11575
diff changeset
66 %! [~,~,Z]=peaks;
4c93cc41da15 codesprint: add demo for surf.m and surfc.m
Kai Habel <kai.habel@gmx.de>
parents: 11575
diff changeset
67 %! surf(Z);
4c93cc41da15 codesprint: add demo for surf.m and surfc.m
Kai Habel <kai.habel@gmx.de>
parents: 11575
diff changeset
68
4c93cc41da15 codesprint: add demo for surf.m and surfc.m
Kai Habel <kai.habel@gmx.de>
parents: 11575
diff changeset
69 %!demo
4c93cc41da15 codesprint: add demo for surf.m and surfc.m
Kai Habel <kai.habel@gmx.de>
parents: 11575
diff changeset
70 %! [~,~,Z]=sombrero;
4c93cc41da15 codesprint: add demo for surf.m and surfc.m
Kai Habel <kai.habel@gmx.de>
parents: 11575
diff changeset
71 %! [Fx,Fy] = gradient(Z);
4c93cc41da15 codesprint: add demo for surf.m and surfc.m
Kai Habel <kai.habel@gmx.de>
parents: 11575
diff changeset
72 %! surf(Z,Fx+Fy);
4c93cc41da15 codesprint: add demo for surf.m and surfc.m
Kai Habel <kai.habel@gmx.de>
parents: 11575
diff changeset
73 %! shading interp;
4c93cc41da15 codesprint: add demo for surf.m and surfc.m
Kai Habel <kai.habel@gmx.de>
parents: 11575
diff changeset
74
4c93cc41da15 codesprint: add demo for surf.m and surfc.m
Kai Habel <kai.habel@gmx.de>
parents: 11575
diff changeset
75 %!demo
4c93cc41da15 codesprint: add demo for surf.m and surfc.m
Kai Habel <kai.habel@gmx.de>
parents: 11575
diff changeset
76 %! [X,Y,Z]=sombrero;
4c93cc41da15 codesprint: add demo for surf.m and surfc.m
Kai Habel <kai.habel@gmx.de>
parents: 11575
diff changeset
77 %! [~,Fy] = gradient(Z);
4c93cc41da15 codesprint: add demo for surf.m and surfc.m
Kai Habel <kai.habel@gmx.de>
parents: 11575
diff changeset
78 %! surf(X,Y,Z,Fy);
4c93cc41da15 codesprint: add demo for surf.m and surfc.m
Kai Habel <kai.habel@gmx.de>
parents: 11575
diff changeset
79 %! shading interp;