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}) |
5378
|
24 ## Given vectors of @var{x}, @var{y}, and @var{z} coordinates, return |
|
25 ## three dimensional arrays corresponding to the @var{x}, @var{y}, and |
|
26 ## @var{z} coordinates of a mesh. Given only @var{x} and @var{y}, |
|
27 ## return matrices corresponding to the @var{x} and @var{y} coordinates |
|
28 ## of a mesh. The rows of @var{xx} are copies of @var{x}, and the |
|
29 ## columns of @var{yy} are copies of @var{y}. If @var{y} is omitted, |
|
30 ## then it is assumed to be the same as @var{x}. |
3407
|
31 ## @end deftypefn |
5053
|
32 ## |
5390
|
33 ## @seealso{mesh, contour} |
1713
|
34 |
2314
|
35 ## Author: jwe |
|
36 |
5378
|
37 function [xx, yy, zz] = meshgrid (x, y, z) |
1713
|
38 |
|
39 if (nargin == 1) |
|
40 y = x; |
|
41 endif |
|
42 if (nargin > 0 && nargin < 3) |
4030
|
43 if (isvector (x) && isvector (y)) |
3803
|
44 xx = ones (length (y), 1) * x(:).'; |
|
45 yy = y(:) * ones (1, length (x)); |
1713
|
46 else |
|
47 error ("meshgrid: arguments must be vectors"); |
|
48 endif |
5378
|
49 elseif (nargin == 3) |
|
50 if (isvector (x) && isvector (y) && isvector (z)) |
|
51 lenx = length (x); |
|
52 leny = length (y); |
|
53 lenz = length (z); |
|
54 xx = repmat (ones (leny, 1) * x(:).', [1, 1, lenz]); |
|
55 yy = repmat (y(:) * ones (1, lenx), [1, 1, lenz]); |
|
56 zz = reshape (repmat (z(:).', lenx*leny, 1)(:), leny, lenx, lenz); |
|
57 else |
|
58 error ("meshgrid: arguments must be vectors"); |
|
59 endif |
1713
|
60 else |
5378
|
61 usage ("[xx, yy, zz] = meshgrid (x, y, z)"); |
1713
|
62 endif |
|
63 |
|
64 endfunction |