2847
|
1 ## Copyright (C) 1996, 1997 John W. Eaton |
2313
|
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 2, or (at your option) |
|
8 ## 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, write to the Free |
5307
|
17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
18 ## 02110-1301, USA. |
1713
|
19 |
3407
|
20 ## -*- texinfo -*- |
5378
|
21 ## @deftypefn {Function File} {[@var{xx}, @var{yy}, @var{zz}] =} meshgrid (@var{x}, @var{y}, @var{z}) |
|
22 ## @deftypefnx {Function File} {[@var{xx}, @var{yy}] =} meshgrid (@var{x}, @var{y}) |
3439
|
23 ## @deftypefnx {Function File} {[@var{xx}, @var{yy}] =} meshgrid (@var{x}) |
5717
|
24 ## Given vectors of @var{x} and @var{y} and @var{z} coordinates, and |
|
25 ## returning 3 arguments, return three dimensional arrays corresponding |
|
26 ## to the @var{x}, @var{y}, and @var{z} coordinates of a mesh. When |
|
27 ## returning only 2 arguments, return matrices corresponding to the |
|
28 ## @var{x} and @var{y} coordinates of a mesh. The rows of @var{xx} are |
|
29 ## copies of @var{x}, and the columns of @var{yy} are copies of @var{y}. |
|
30 ## If @var{y} is omitted, then it is assumed to be the same as @var{x}, |
|
31 ## and @var{z} is assumed the same as @var{y}. |
5642
|
32 ## @seealso{mesh, contour} |
3407
|
33 ## @end deftypefn |
1713
|
34 |
2314
|
35 ## Author: jwe |
|
36 |
5378
|
37 function [xx, yy, zz] = meshgrid (x, y, z) |
1713
|
38 |
5717
|
39 if (nargin == 0 || nargin > 3) |
|
40 usage ("[xx, yy, zz] = meshgrid (x, y, z)"); |
|
41 endif |
|
42 |
|
43 if (nargin < 2) |
1713
|
44 y = x; |
|
45 endif |
5717
|
46 |
|
47 if (nargout < 3) |
4030
|
48 if (isvector (x) && isvector (y)) |
3803
|
49 xx = ones (length (y), 1) * x(:).'; |
|
50 yy = y(:) * ones (1, length (x)); |
1713
|
51 else |
|
52 error ("meshgrid: arguments must be vectors"); |
|
53 endif |
|
54 else |
5717
|
55 if (nargin < 3) |
|
56 z = y; |
|
57 endif |
|
58 if (isvector (x) && isvector (y) && isvector (z)) |
|
59 lenx = length (x); |
|
60 leny = length (y); |
|
61 lenz = length (z); |
|
62 xx = repmat (ones (leny, 1) * x(:).', [1, 1, lenz]); |
|
63 yy = repmat (y(:) * ones (1, lenx), [1, 1, lenz]); |
|
64 zz = reshape (repmat (z(:).', lenx*leny, 1)(:), leny, lenx, lenz); |
|
65 else |
|
66 error ("meshgrid: arguments must be vectors"); |
|
67 endif |
1713
|
68 endif |
|
69 |
|
70 endfunction |