Mercurial > hg > octave-nkf
annotate scripts/plot/meshgrid.m @ 9245:16f53d29049f
update copyright notices
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 22 May 2009 10:46:00 -0400 |
parents | 923c7cb7f13f |
children | be55736a0783 |
rev | line source |
---|---|
9245 | 1 ## Copyright (C) 1996, 1997, 2000, 2001, 2002, 2004, 2005, 2006, 2007, 2009 |
7017 | 2 ## John W. Eaton |
2313 | 3 ## |
4 ## This file is part of Octave. | |
5 ## | |
6 ## Octave is free software; you can redistribute it and/or modify it | |
7 ## under the terms of the GNU General Public License as published by | |
7016 | 8 ## the Free Software Foundation; either version 3 of the License, or (at |
9 ## your option) any later version. | |
2313 | 10 ## |
11 ## Octave is distributed in the hope that it will be useful, but | |
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 ## General Public License for more details. | |
15 ## | |
16 ## You should have received a copy of the GNU General Public License | |
7016 | 17 ## along with Octave; see the file COPYING. If not, see |
18 ## <http://www.gnu.org/licenses/>. | |
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 |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
7017
diff
changeset
|
25 ## returning 3 arguments, return three-dimensional arrays corresponding |
5717 | 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) |
6046 | 40 print_usage (); |
5717 | 41 endif |
42 | |
43 if (nargin < 2) | |
1713 | 44 y = x; |
45 endif | |
5717 | 46 |
6813 | 47 ## Use repmat to ensure that the result values have the same type as |
48 ## the arguments. | |
49 | |
5717 | 50 if (nargout < 3) |
4030 | 51 if (isvector (x) && isvector (y)) |
6813 | 52 xx = repmat (x(:).', length (y), 1); |
53 yy = repmat (y(:), 1, length (x)); | |
1713 | 54 else |
55 error ("meshgrid: arguments must be vectors"); | |
56 endif | |
57 else | |
5717 | 58 if (nargin < 3) |
59 z = y; | |
60 endif | |
61 if (isvector (x) && isvector (y) && isvector (z)) | |
62 lenx = length (x); | |
63 leny = length (y); | |
64 lenz = length (z); | |
6813 | 65 xx = repmat (repmat (x(:).', leny, 1), [1, 1, lenz]); |
66 yy = repmat (repmat (y(:), 1, lenx), [1, 1, lenz]); | |
5717 | 67 zz = reshape (repmat (z(:).', lenx*leny, 1)(:), leny, lenx, lenz); |
68 else | |
6813 | 69 error ("meshgrid: arguments must be vectors"); |
5717 | 70 endif |
1713 | 71 endif |
72 | |
73 endfunction |