Mercurial > hg > octave-lyh
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 |
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 | 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}) | |
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 | 26 ## @var{z} correspond to different @var{y} values. |
27 ## @seealso{meshgrid, mesh, contour} | |
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 | 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 | 34 endif |
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 | 50 z = varargin{1}; |
7207 | 51 [m, n] = size (z); |
7216 | 52 x = 1:n; |
53 y = (1:m).'; | |
7207 | 54 else |
7208 | 55 x = varargin{1}; |
56 y = varargin{2}; | |
57 z = varargin{3}; | |
7207 | 58 endif |
59 | |
60 if (isvector (x) && isvector (y)) | |
61 x = [x(1), x(:).', x(end)]; | |
62 y = [y(1); y(:); y(end)]; | |
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 | 70 endif |
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 | 76 |
16985
c9346014fed2
Validate inputs are real for mesh, meshc, meshz functions.
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
77 oldax = gca (); |
7215 | 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 | 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 | 83 end_unwind_protect |
84 | |
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 | 87 endif |
7207 | 88 |
89 endfunction | |
16985
c9346014fed2
Validate inputs are real for mesh, meshc, meshz functions.
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
90 |