annotate scripts/plot/meshgrid.m @ 1713:d9e42d0bab09

[project @ 1996-01-08 02:22:55 by jwe] Initial revision
author jwe
date Mon, 08 Jan 1996 02:22:55 +0000
parents
children 5d29638dd524
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1713
d9e42d0bab09 [project @ 1996-01-08 02:22:55 by jwe]
jwe
parents:
diff changeset
1 # Copyright (C) 1993, 1994, 1995 John W. Eaton
d9e42d0bab09 [project @ 1996-01-08 02:22:55 by jwe]
jwe
parents:
diff changeset
2 #
d9e42d0bab09 [project @ 1996-01-08 02:22:55 by jwe]
jwe
parents:
diff changeset
3 # This file is part of Octave.
d9e42d0bab09 [project @ 1996-01-08 02:22:55 by jwe]
jwe
parents:
diff changeset
4 #
d9e42d0bab09 [project @ 1996-01-08 02:22:55 by jwe]
jwe
parents:
diff changeset
5 # Octave is free software; you can redistribute it and/or modify it
d9e42d0bab09 [project @ 1996-01-08 02:22:55 by jwe]
jwe
parents:
diff changeset
6 # under the terms of the GNU General Public License as published by the
d9e42d0bab09 [project @ 1996-01-08 02:22:55 by jwe]
jwe
parents:
diff changeset
7 # Free Software Foundation; either version 2, or (at your option) any
d9e42d0bab09 [project @ 1996-01-08 02:22:55 by jwe]
jwe
parents:
diff changeset
8 # later version.
d9e42d0bab09 [project @ 1996-01-08 02:22:55 by jwe]
jwe
parents:
diff changeset
9 #
d9e42d0bab09 [project @ 1996-01-08 02:22:55 by jwe]
jwe
parents:
diff changeset
10 # Octave is distributed in the hope that it will be useful, but WITHOUT
d9e42d0bab09 [project @ 1996-01-08 02:22:55 by jwe]
jwe
parents:
diff changeset
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d9e42d0bab09 [project @ 1996-01-08 02:22:55 by jwe]
jwe
parents:
diff changeset
12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
d9e42d0bab09 [project @ 1996-01-08 02:22:55 by jwe]
jwe
parents:
diff changeset
13 # for more details.
d9e42d0bab09 [project @ 1996-01-08 02:22:55 by jwe]
jwe
parents:
diff changeset
14 #
d9e42d0bab09 [project @ 1996-01-08 02:22:55 by jwe]
jwe
parents:
diff changeset
15 # You should have received a copy of the GNU General Public License
d9e42d0bab09 [project @ 1996-01-08 02:22:55 by jwe]
jwe
parents:
diff changeset
16 # along with Octave; see the file COPYING. If not, write to the Free
d9e42d0bab09 [project @ 1996-01-08 02:22:55 by jwe]
jwe
parents:
diff changeset
17 # Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
d9e42d0bab09 [project @ 1996-01-08 02:22:55 by jwe]
jwe
parents:
diff changeset
18
d9e42d0bab09 [project @ 1996-01-08 02:22:55 by jwe]
jwe
parents:
diff changeset
19 function [xx, yy] = meshgrid (x, y)
d9e42d0bab09 [project @ 1996-01-08 02:22:55 by jwe]
jwe
parents:
diff changeset
20
d9e42d0bab09 [project @ 1996-01-08 02:22:55 by jwe]
jwe
parents:
diff changeset
21 # usage: [xx, yy] = meshgrid (x, y)
d9e42d0bab09 [project @ 1996-01-08 02:22:55 by jwe]
jwe
parents:
diff changeset
22 #
d9e42d0bab09 [project @ 1996-01-08 02:22:55 by jwe]
jwe
parents:
diff changeset
23 # Given vectors of x and y coordinates, return two matrices corresponding
d9e42d0bab09 [project @ 1996-01-08 02:22:55 by jwe]
jwe
parents:
diff changeset
24 # to the x and y coordinates of a mesh. The rows of xx are copies of x,
d9e42d0bab09 [project @ 1996-01-08 02:22:55 by jwe]
jwe
parents:
diff changeset
25 # and the columns of yy are copies of y.
d9e42d0bab09 [project @ 1996-01-08 02:22:55 by jwe]
jwe
parents:
diff changeset
26 #
d9e42d0bab09 [project @ 1996-01-08 02:22:55 by jwe]
jwe
parents:
diff changeset
27 # [xx, yy] = meshgrid (x) is an abbreviation for [xx, yy] = meshgrid (x, x).
d9e42d0bab09 [project @ 1996-01-08 02:22:55 by jwe]
jwe
parents:
diff changeset
28 #
d9e42d0bab09 [project @ 1996-01-08 02:22:55 by jwe]
jwe
parents:
diff changeset
29 # See also: plot, semilogx, semilogy, loglog, polar, mesh, meshdom, contour,
d9e42d0bab09 [project @ 1996-01-08 02:22:55 by jwe]
jwe
parents:
diff changeset
30 # bar, stairs, gplot, gsplot, replot, xlabel, ylabel, title
d9e42d0bab09 [project @ 1996-01-08 02:22:55 by jwe]
jwe
parents:
diff changeset
31
d9e42d0bab09 [project @ 1996-01-08 02:22:55 by jwe]
jwe
parents:
diff changeset
32 if (nargin == 1)
d9e42d0bab09 [project @ 1996-01-08 02:22:55 by jwe]
jwe
parents:
diff changeset
33 y = x;
d9e42d0bab09 [project @ 1996-01-08 02:22:55 by jwe]
jwe
parents:
diff changeset
34 endif
d9e42d0bab09 [project @ 1996-01-08 02:22:55 by jwe]
jwe
parents:
diff changeset
35 if (nargin > 0 && nargin < 3)
d9e42d0bab09 [project @ 1996-01-08 02:22:55 by jwe]
jwe
parents:
diff changeset
36 if (is_vector (x) && is_vector (y))
d9e42d0bab09 [project @ 1996-01-08 02:22:55 by jwe]
jwe
parents:
diff changeset
37 xlen = length (x);
d9e42d0bab09 [project @ 1996-01-08 02:22:55 by jwe]
jwe
parents:
diff changeset
38 ylen = length (y);
d9e42d0bab09 [project @ 1996-01-08 02:22:55 by jwe]
jwe
parents:
diff changeset
39 xx = zeros (ylen, xlen);
d9e42d0bab09 [project @ 1996-01-08 02:22:55 by jwe]
jwe
parents:
diff changeset
40 yy = zeros (ylen, xlen);
d9e42d0bab09 [project @ 1996-01-08 02:22:55 by jwe]
jwe
parents:
diff changeset
41 if (columns (x) == 1)
d9e42d0bab09 [project @ 1996-01-08 02:22:55 by jwe]
jwe
parents:
diff changeset
42 x = x';
d9e42d0bab09 [project @ 1996-01-08 02:22:55 by jwe]
jwe
parents:
diff changeset
43 endif
d9e42d0bab09 [project @ 1996-01-08 02:22:55 by jwe]
jwe
parents:
diff changeset
44 if (rows (y) == 1)
d9e42d0bab09 [project @ 1996-01-08 02:22:55 by jwe]
jwe
parents:
diff changeset
45 y = y';
d9e42d0bab09 [project @ 1996-01-08 02:22:55 by jwe]
jwe
parents:
diff changeset
46 endif
d9e42d0bab09 [project @ 1996-01-08 02:22:55 by jwe]
jwe
parents:
diff changeset
47 for i = 1:ylen
d9e42d0bab09 [project @ 1996-01-08 02:22:55 by jwe]
jwe
parents:
diff changeset
48 xx(i,:) = x;
d9e42d0bab09 [project @ 1996-01-08 02:22:55 by jwe]
jwe
parents:
diff changeset
49 endfor
d9e42d0bab09 [project @ 1996-01-08 02:22:55 by jwe]
jwe
parents:
diff changeset
50 for i = 1:xlen
d9e42d0bab09 [project @ 1996-01-08 02:22:55 by jwe]
jwe
parents:
diff changeset
51 yy(:,i) = y;
d9e42d0bab09 [project @ 1996-01-08 02:22:55 by jwe]
jwe
parents:
diff changeset
52 endfor
d9e42d0bab09 [project @ 1996-01-08 02:22:55 by jwe]
jwe
parents:
diff changeset
53 else
d9e42d0bab09 [project @ 1996-01-08 02:22:55 by jwe]
jwe
parents:
diff changeset
54 error ("meshgrid: arguments must be vectors");
d9e42d0bab09 [project @ 1996-01-08 02:22:55 by jwe]
jwe
parents:
diff changeset
55 endif
d9e42d0bab09 [project @ 1996-01-08 02:22:55 by jwe]
jwe
parents:
diff changeset
56 else
d9e42d0bab09 [project @ 1996-01-08 02:22:55 by jwe]
jwe
parents:
diff changeset
57 usage ("[xx, yy] = meshgrid (x, y)");
d9e42d0bab09 [project @ 1996-01-08 02:22:55 by jwe]
jwe
parents:
diff changeset
58 endif
d9e42d0bab09 [project @ 1996-01-08 02:22:55 by jwe]
jwe
parents:
diff changeset
59
d9e42d0bab09 [project @ 1996-01-08 02:22:55 by jwe]
jwe
parents:
diff changeset
60 endfunction