annotate scripts/plot/meshz.m @ 16985:c9346014fed2

Validate inputs are real for mesh, meshc, meshz functions. Rename internal helper variables for greater clarity. * scripts/plot/mesh.m: Validate inputs are real. Use htmp for temporary handle. * scripts/plot/meshc.m: Validate inputs are real. Use htmp for temporary handle. * scripts/plot/meshz.m: Validate inputs are real. Use htmp for temporary handle. Use cellfun to replace for loop in input validation. Use oldax for saved axes handle.
author Rik <rik@octave.org>
date Sun, 14 Jul 2013 14:12:33 -0700
parents c2dbdeaa25df
children 328b579e08e9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14138
72c96de7a403 maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
1 ## Copyright (C) 2007-2012 David Bateman
7207
71c03c7239fb [project @ 2007-11-28 02:19:25 by jwe]
jwe
parents:
diff changeset
2 ##
71c03c7239fb [project @ 2007-11-28 02:19:25 by jwe]
jwe
parents:
diff changeset
3 ## This file is part of Octave.
71c03c7239fb [project @ 2007-11-28 02:19:25 by jwe]
jwe
parents:
diff changeset
4 ##
71c03c7239fb [project @ 2007-11-28 02:19:25 by jwe]
jwe
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
71c03c7239fb [project @ 2007-11-28 02:19:25 by jwe]
jwe
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by
71c03c7239fb [project @ 2007-11-28 02:19:25 by jwe]
jwe
parents:
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
71c03c7239fb [project @ 2007-11-28 02:19:25 by jwe]
jwe
parents:
diff changeset
8 ## your option) any later version.
71c03c7239fb [project @ 2007-11-28 02:19:25 by jwe]
jwe
parents:
diff changeset
9 ##
71c03c7239fb [project @ 2007-11-28 02:19:25 by jwe]
jwe
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
71c03c7239fb [project @ 2007-11-28 02:19:25 by jwe]
jwe
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
71c03c7239fb [project @ 2007-11-28 02:19:25 by jwe]
jwe
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
71c03c7239fb [project @ 2007-11-28 02:19:25 by jwe]
jwe
parents:
diff changeset
13 ## General Public License for more details.
71c03c7239fb [project @ 2007-11-28 02:19:25 by jwe]
jwe
parents:
diff changeset
14 ##
71c03c7239fb [project @ 2007-11-28 02:19:25 by jwe]
jwe
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
71c03c7239fb [project @ 2007-11-28 02:19:25 by jwe]
jwe
parents:
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
71c03c7239fb [project @ 2007-11-28 02:19:25 by jwe]
jwe
parents:
diff changeset
17 ## <http://www.gnu.org/licenses/>.
71c03c7239fb [project @ 2007-11-28 02:19:25 by jwe]
jwe
parents:
diff changeset
18
71c03c7239fb [project @ 2007-11-28 02:19:25 by jwe]
jwe
parents:
diff changeset
19 ## -*- texinfo -*-
71c03c7239fb [project @ 2007-11-28 02:19:25 by jwe]
jwe
parents:
diff changeset
20 ## @deftypefn {Function File} {} meshz (@var{x}, @var{y}, @var{z})
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
21 ## Plot a curtain mesh given matrices @var{x}, and @var{y} from
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
22 ## @code{meshgrid} and a matrix @var{z} corresponding to the @var{x} and
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
23 ## @var{y} coordinates of the mesh. If @var{x} and @var{y} are vectors,
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
24 ## then a typical vertex is (@var{x}(j), @var{y}(i), @var{z}(i,j)). Thus,
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
25 ## columns of @var{z} correspond to different @var{x} values and rows of
7207
71c03c7239fb [project @ 2007-11-28 02:19:25 by jwe]
jwe
parents:
diff changeset
26 ## @var{z} correspond to different @var{y} values.
71c03c7239fb [project @ 2007-11-28 02:19:25 by jwe]
jwe
parents:
diff changeset
27 ## @seealso{meshgrid, mesh, contour}
71c03c7239fb [project @ 2007-11-28 02:19:25 by jwe]
jwe
parents:
diff changeset
28 ## @end deftypefn
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
29
16985
c9346014fed2 Validate inputs are real for mesh, meshc, meshz functions.
Rik <rik@octave.org>
parents: 14872
diff changeset
30 function h = meshz (varargin)
7207
71c03c7239fb [project @ 2007-11-28 02:19:25 by jwe]
jwe
parents:
diff changeset
31
16985
c9346014fed2 Validate inputs are real for mesh, meshc, meshz functions.
Rik <rik@octave.org>
parents: 14872
diff changeset
32 if (! all (cellfun ("isreal", varargin)))
c9346014fed2 Validate inputs are real for mesh, meshc, meshz functions.
Rik <rik@octave.org>
parents: 14872
diff changeset
33 error ("meshz: X, Y, Z, C arguments must be real");
7207
71c03c7239fb [project @ 2007-11-28 02:19:25 by jwe]
jwe
parents:
diff changeset
34 endif
71c03c7239fb [project @ 2007-11-28 02:19:25 by jwe]
jwe
parents:
diff changeset
35
16985
c9346014fed2 Validate inputs are real for mesh, meshc, meshz functions.
Rik <rik@octave.org>
parents: 14872
diff changeset
36 [ax, varargin, nargin] = __plt_get_axis_arg__ ("meshz", varargin{:});
c9346014fed2 Validate inputs are real for mesh, meshc, meshz functions.
Rik <rik@octave.org>
parents: 14872
diff changeset
37
c9346014fed2 Validate inputs are real for mesh, meshc, meshz functions.
Rik <rik@octave.org>
parents: 14872
diff changeset
38 ## Find where property/value pairs start
c9346014fed2 Validate inputs are real for mesh, meshc, meshz functions.
Rik <rik@octave.org>
parents: 14872
diff changeset
39 charidx = find (cellfun ("isclass", varargin, "char"), 1);
c9346014fed2 Validate inputs are real for mesh, meshc, meshz functions.
Rik <rik@octave.org>
parents: 14872
diff changeset
40
c9346014fed2 Validate inputs are real for mesh, meshc, meshz functions.
Rik <rik@octave.org>
parents: 14872
diff changeset
41 if (isempty (charidx))
c9346014fed2 Validate inputs are real for mesh, meshc, meshz functions.
Rik <rik@octave.org>
parents: 14872
diff changeset
42 if (nargin == 2 || nargin == 4)
c9346014fed2 Validate inputs are real for mesh, meshc, meshz functions.
Rik <rik@octave.org>
parents: 14872
diff changeset
43 charidx = nargin; # bundle C matrix back into varargin
c9346014fed2 Validate inputs are real for mesh, meshc, meshz functions.
Rik <rik@octave.org>
parents: 14872
diff changeset
44 else
c9346014fed2 Validate inputs are real for mesh, meshc, meshz functions.
Rik <rik@octave.org>
parents: 14872
diff changeset
45 charidx = nargin + 1;
c9346014fed2 Validate inputs are real for mesh, meshc, meshz functions.
Rik <rik@octave.org>
parents: 14872
diff changeset
46 endif
c9346014fed2 Validate inputs are real for mesh, meshc, meshz functions.
Rik <rik@octave.org>
parents: 14872
diff changeset
47 endif
c9346014fed2 Validate inputs are real for mesh, meshc, meshz functions.
Rik <rik@octave.org>
parents: 14872
diff changeset
48
c9346014fed2 Validate inputs are real for mesh, meshc, meshz functions.
Rik <rik@octave.org>
parents: 14872
diff changeset
49 if (charidx == 2)
7208
a730e47fda4d [project @ 2007-11-28 02:32:41 by jwe]
jwe
parents: 7207
diff changeset
50 z = varargin{1};
7207
71c03c7239fb [project @ 2007-11-28 02:19:25 by jwe]
jwe
parents:
diff changeset
51 [m, n] = size (z);
7216
5389a52df87b [project @ 2007-11-29 19:07:29 by jwe]
jwe
parents: 7215
diff changeset
52 x = 1:n;
5389a52df87b [project @ 2007-11-29 19:07:29 by jwe]
jwe
parents: 7215
diff changeset
53 y = (1:m).';
7207
71c03c7239fb [project @ 2007-11-28 02:19:25 by jwe]
jwe
parents:
diff changeset
54 else
7208
a730e47fda4d [project @ 2007-11-28 02:32:41 by jwe]
jwe
parents: 7207
diff changeset
55 x = varargin{1};
a730e47fda4d [project @ 2007-11-28 02:32:41 by jwe]
jwe
parents: 7207
diff changeset
56 y = varargin{2};
a730e47fda4d [project @ 2007-11-28 02:32:41 by jwe]
jwe
parents: 7207
diff changeset
57 z = varargin{3};
7207
71c03c7239fb [project @ 2007-11-28 02:19:25 by jwe]
jwe
parents:
diff changeset
58 endif
71c03c7239fb [project @ 2007-11-28 02:19:25 by jwe]
jwe
parents:
diff changeset
59
71c03c7239fb [project @ 2007-11-28 02:19:25 by jwe]
jwe
parents:
diff changeset
60 if (isvector (x) && isvector (y))
71c03c7239fb [project @ 2007-11-28 02:19:25 by jwe]
jwe
parents:
diff changeset
61 x = [x(1), x(:).', x(end)];
71c03c7239fb [project @ 2007-11-28 02:19:25 by jwe]
jwe
parents:
diff changeset
62 y = [y(1); y(:); y(end)];
71c03c7239fb [project @ 2007-11-28 02:19:25 by jwe]
jwe
parents:
diff changeset
63 else
16985
c9346014fed2 Validate inputs are real for mesh, meshc, meshz functions.
Rik <rik@octave.org>
parents: 14872
diff changeset
64 x = [x(1,1), x(1,:), x(1,end);
c9346014fed2 Validate inputs are real for mesh, meshc, meshz functions.
Rik <rik@octave.org>
parents: 14872
diff changeset
65 x(:,1), x, x(:,end);
c9346014fed2 Validate inputs are real for mesh, meshc, meshz functions.
Rik <rik@octave.org>
parents: 14872
diff changeset
66 x(end,1), x(end,:), x(end,end)];
c9346014fed2 Validate inputs are real for mesh, meshc, meshz functions.
Rik <rik@octave.org>
parents: 14872
diff changeset
67 y = [y(1,1), y(1,:), y(1,end);
c9346014fed2 Validate inputs are real for mesh, meshc, meshz functions.
Rik <rik@octave.org>
parents: 14872
diff changeset
68 y(:,1), y, y(:,end);
c9346014fed2 Validate inputs are real for mesh, meshc, meshz functions.
Rik <rik@octave.org>
parents: 14872
diff changeset
69 y(end,1), y(end,:), y(end,end)];
7207
71c03c7239fb [project @ 2007-11-28 02:19:25 by jwe]
jwe
parents:
diff changeset
70 endif
71c03c7239fb [project @ 2007-11-28 02:19:25 by jwe]
jwe
parents:
diff changeset
71
14868
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
72 zref = min (z(isfinite (z)));
14872
c2dbdeaa25df maint: use rows() and columns() to clarify m-files.
Rik <octave@nomad.inbox5.com>
parents: 14868
diff changeset
73 z = [zref .* ones(1, columns(z) + 2);
c2dbdeaa25df maint: use rows() and columns() to clarify m-files.
Rik <octave@nomad.inbox5.com>
parents: 14868
diff changeset
74 zref .* ones(rows(z), 1), z, zref .* ones(rows(z), 1);
c2dbdeaa25df maint: use rows() and columns() to clarify m-files.
Rik <octave@nomad.inbox5.com>
parents: 14868
diff changeset
75 zref.* ones(1, columns(z) + 2)];
7207
71c03c7239fb [project @ 2007-11-28 02:19:25 by jwe]
jwe
parents:
diff changeset
76
16985
c9346014fed2 Validate inputs are real for mesh, meshc, meshz functions.
Rik <rik@octave.org>
parents: 14872
diff changeset
77 oldax = gca ();
7215
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7208
diff changeset
78 unwind_protect
16985
c9346014fed2 Validate inputs are real for mesh, meshc, meshz functions.
Rik <rik@octave.org>
parents: 14872
diff changeset
79 axes (ax);
c9346014fed2 Validate inputs are real for mesh, meshc, meshz functions.
Rik <rik@octave.org>
parents: 14872
diff changeset
80 htmp = mesh (x, y, z, varargin{charidx:end});
7215
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7208
diff changeset
81 unwind_protect_cleanup
16985
c9346014fed2 Validate inputs are real for mesh, meshc, meshz functions.
Rik <rik@octave.org>
parents: 14872
diff changeset
82 axes (oldax);
7215
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7208
diff changeset
83 end_unwind_protect
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7208
diff changeset
84
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7208
diff changeset
85 if (nargout > 0)
16985
c9346014fed2 Validate inputs are real for mesh, meshc, meshz functions.
Rik <rik@octave.org>
parents: 14872
diff changeset
86 h = htmp;
7215
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7208
diff changeset
87 endif
7207
71c03c7239fb [project @ 2007-11-28 02:19:25 by jwe]
jwe
parents:
diff changeset
88
71c03c7239fb [project @ 2007-11-28 02:19:25 by jwe]
jwe
parents:
diff changeset
89 endfunction
16985
c9346014fed2 Validate inputs are real for mesh, meshc, meshz functions.
Rik <rik@octave.org>
parents: 14872
diff changeset
90