annotate scripts/plot/meshgrid.m @ 5717:34cda7d94c08

[project @ 2006-03-27 22:26:18 by jwe]
author jwe
date Mon, 27 Mar 2006 22:26:21 +0000
parents 2618a0750ae6
children 34f96dd5441b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2847
8b262e771614 [project @ 1997-03-27 16:18:26 by jwe]
jwe
parents: 2710
diff changeset
1 ## Copyright (C) 1996, 1997 John W. Eaton
2313
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
2 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
3 ## This file is part of Octave.
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
4 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
6 ## under the terms of the GNU General Public License as published by
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
7 ## the Free Software Foundation; either version 2, or (at your option)
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
8 ## any later version.
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
9 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
13 ## General Public License for more details.
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
14 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
15 ## You should have received a copy of the GNU General Public License
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
16 ## along with Octave; see the file COPYING. If not, write to the Free
5307
4c8a2e4e0717 [project @ 2005-04-26 19:24:27 by jwe]
jwe
parents: 5214
diff changeset
17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
4c8a2e4e0717 [project @ 2005-04-26 19:24:27 by jwe]
jwe
parents: 5214
diff changeset
18 ## 02110-1301, USA.
1713
d9e42d0bab09 [project @ 1996-01-08 02:22:55 by jwe]
jwe
parents:
diff changeset
19
3407
5e0a0b1cba43 [project @ 2000-01-06 03:13:55 by jwe]
jwe
parents: 2847
diff changeset
20 ## -*- texinfo -*-
5378
b2a5596a3f7b [project @ 2005-06-02 16:01:25 by jwe]
jwe
parents: 5307
diff changeset
21 ## @deftypefn {Function File} {[@var{xx}, @var{yy}, @var{zz}] =} meshgrid (@var{x}, @var{y}, @var{z})
b2a5596a3f7b [project @ 2005-06-02 16:01:25 by jwe]
jwe
parents: 5307
diff changeset
22 ## @deftypefnx {Function File} {[@var{xx}, @var{yy}] =} meshgrid (@var{x}, @var{y})
3439
3234a698073a [project @ 2000-01-14 09:51:14 by jwe]
jwe
parents: 3408
diff changeset
23 ## @deftypefnx {Function File} {[@var{xx}, @var{yy}] =} meshgrid (@var{x})
5717
34cda7d94c08 [project @ 2006-03-27 22:26:18 by jwe]
jwe
parents: 5642
diff changeset
24 ## Given vectors of @var{x} and @var{y} and @var{z} coordinates, and
34cda7d94c08 [project @ 2006-03-27 22:26:18 by jwe]
jwe
parents: 5642
diff changeset
25 ## returning 3 arguments, return three dimensional arrays corresponding
34cda7d94c08 [project @ 2006-03-27 22:26:18 by jwe]
jwe
parents: 5642
diff changeset
26 ## to the @var{x}, @var{y}, and @var{z} coordinates of a mesh. When
34cda7d94c08 [project @ 2006-03-27 22:26:18 by jwe]
jwe
parents: 5642
diff changeset
27 ## returning only 2 arguments, return matrices corresponding to the
34cda7d94c08 [project @ 2006-03-27 22:26:18 by jwe]
jwe
parents: 5642
diff changeset
28 ## @var{x} and @var{y} coordinates of a mesh. The rows of @var{xx} are
34cda7d94c08 [project @ 2006-03-27 22:26:18 by jwe]
jwe
parents: 5642
diff changeset
29 ## copies of @var{x}, and the columns of @var{yy} are copies of @var{y}.
34cda7d94c08 [project @ 2006-03-27 22:26:18 by jwe]
jwe
parents: 5642
diff changeset
30 ## If @var{y} is omitted, then it is assumed to be the same as @var{x},
34cda7d94c08 [project @ 2006-03-27 22:26:18 by jwe]
jwe
parents: 5642
diff changeset
31 ## and @var{z} is assumed the same as @var{y}.
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5390
diff changeset
32 ## @seealso{mesh, contour}
3407
5e0a0b1cba43 [project @ 2000-01-06 03:13:55 by jwe]
jwe
parents: 2847
diff changeset
33 ## @end deftypefn
1713
d9e42d0bab09 [project @ 1996-01-08 02:22:55 by jwe]
jwe
parents:
diff changeset
34
2314
949ab8eba8bc [project @ 1996-07-12 03:58:02 by jwe]
jwe
parents: 2313
diff changeset
35 ## Author: jwe
949ab8eba8bc [project @ 1996-07-12 03:58:02 by jwe]
jwe
parents: 2313
diff changeset
36
5378
b2a5596a3f7b [project @ 2005-06-02 16:01:25 by jwe]
jwe
parents: 5307
diff changeset
37 function [xx, yy, zz] = meshgrid (x, y, z)
1713
d9e42d0bab09 [project @ 1996-01-08 02:22:55 by jwe]
jwe
parents:
diff changeset
38
5717
34cda7d94c08 [project @ 2006-03-27 22:26:18 by jwe]
jwe
parents: 5642
diff changeset
39 if (nargin == 0 || nargin > 3)
34cda7d94c08 [project @ 2006-03-27 22:26:18 by jwe]
jwe
parents: 5642
diff changeset
40 usage ("[xx, yy, zz] = meshgrid (x, y, z)");
34cda7d94c08 [project @ 2006-03-27 22:26:18 by jwe]
jwe
parents: 5642
diff changeset
41 endif
34cda7d94c08 [project @ 2006-03-27 22:26:18 by jwe]
jwe
parents: 5642
diff changeset
42
34cda7d94c08 [project @ 2006-03-27 22:26:18 by jwe]
jwe
parents: 5642
diff changeset
43 if (nargin < 2)
1713
d9e42d0bab09 [project @ 1996-01-08 02:22:55 by jwe]
jwe
parents:
diff changeset
44 y = x;
d9e42d0bab09 [project @ 1996-01-08 02:22:55 by jwe]
jwe
parents:
diff changeset
45 endif
5717
34cda7d94c08 [project @ 2006-03-27 22:26:18 by jwe]
jwe
parents: 5642
diff changeset
46
34cda7d94c08 [project @ 2006-03-27 22:26:18 by jwe]
jwe
parents: 5642
diff changeset
47 if (nargout < 3)
4030
22bd65326ec1 [project @ 2002-08-09 18:58:13 by jwe]
jwe
parents: 3803
diff changeset
48 if (isvector (x) && isvector (y))
3803
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents: 3709
diff changeset
49 xx = ones (length (y), 1) * x(:).';
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents: 3709
diff changeset
50 yy = y(:) * ones (1, length (x));
1713
d9e42d0bab09 [project @ 1996-01-08 02:22:55 by jwe]
jwe
parents:
diff changeset
51 else
d9e42d0bab09 [project @ 1996-01-08 02:22:55 by jwe]
jwe
parents:
diff changeset
52 error ("meshgrid: arguments must be vectors");
d9e42d0bab09 [project @ 1996-01-08 02:22:55 by jwe]
jwe
parents:
diff changeset
53 endif
d9e42d0bab09 [project @ 1996-01-08 02:22:55 by jwe]
jwe
parents:
diff changeset
54 else
5717
34cda7d94c08 [project @ 2006-03-27 22:26:18 by jwe]
jwe
parents: 5642
diff changeset
55 if (nargin < 3)
34cda7d94c08 [project @ 2006-03-27 22:26:18 by jwe]
jwe
parents: 5642
diff changeset
56 z = y;
34cda7d94c08 [project @ 2006-03-27 22:26:18 by jwe]
jwe
parents: 5642
diff changeset
57 endif
34cda7d94c08 [project @ 2006-03-27 22:26:18 by jwe]
jwe
parents: 5642
diff changeset
58 if (isvector (x) && isvector (y) && isvector (z))
34cda7d94c08 [project @ 2006-03-27 22:26:18 by jwe]
jwe
parents: 5642
diff changeset
59 lenx = length (x);
34cda7d94c08 [project @ 2006-03-27 22:26:18 by jwe]
jwe
parents: 5642
diff changeset
60 leny = length (y);
34cda7d94c08 [project @ 2006-03-27 22:26:18 by jwe]
jwe
parents: 5642
diff changeset
61 lenz = length (z);
34cda7d94c08 [project @ 2006-03-27 22:26:18 by jwe]
jwe
parents: 5642
diff changeset
62 xx = repmat (ones (leny, 1) * x(:).', [1, 1, lenz]);
34cda7d94c08 [project @ 2006-03-27 22:26:18 by jwe]
jwe
parents: 5642
diff changeset
63 yy = repmat (y(:) * ones (1, lenx), [1, 1, lenz]);
34cda7d94c08 [project @ 2006-03-27 22:26:18 by jwe]
jwe
parents: 5642
diff changeset
64 zz = reshape (repmat (z(:).', lenx*leny, 1)(:), leny, lenx, lenz);
34cda7d94c08 [project @ 2006-03-27 22:26:18 by jwe]
jwe
parents: 5642
diff changeset
65 else
34cda7d94c08 [project @ 2006-03-27 22:26:18 by jwe]
jwe
parents: 5642
diff changeset
66 error ("meshgrid: arguments must be vectors");
34cda7d94c08 [project @ 2006-03-27 22:26:18 by jwe]
jwe
parents: 5642
diff changeset
67 endif
1713
d9e42d0bab09 [project @ 1996-01-08 02:22:55 by jwe]
jwe
parents:
diff changeset
68 endif
d9e42d0bab09 [project @ 1996-01-08 02:22:55 by jwe]
jwe
parents:
diff changeset
69
d9e42d0bab09 [project @ 1996-01-08 02:22:55 by jwe]
jwe
parents:
diff changeset
70 endfunction