Mercurial > hg > octave-nkf
annotate scripts/plot/meshgrid.m @ 15137:16a6b0a6855d gui
GUI: support for octave arguments and integrate with run-octave.
* src/octave.h (octave_initialize_interpreter, octave_execute_interpreter):
New functions.
(octave_cmdline_argc, octave_cmdline_argv, octave_embedded): New variables.
* src/octave.cc (octave_cmdline_argc, octave_cmdline_argv, octave_embedded):
New variables.
(octave_initialize_interpreter, octave_execute_interpreter): New functions.
(octave_main): Rewrite using them.
* run-octave.in (octave_executable): New variable.
(-gui): New option flag.
* gui/src/octave-adapter/octave-main-thread.cc (octave_main_thread::run):
Use octave_execute_interpreter.
* gui/src/octave-gui.cc (dissociate_terminal): New function.
(main): Use it. Also use octave_initialize_interpreter.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sun, 05 Aug 2012 16:15:58 -0400 |
parents | f3d52523cde1 |
children | eaab03308c0b |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
13263
diff
changeset
|
1 ## Copyright (C) 1996-2012 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 | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
2313 | 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 | |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
1713 | 18 |
3407 | 19 ## -*- texinfo -*- |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
9245
diff
changeset
|
20 ## @deftypefn {Function File} {[@var{xx}, @var{yy}, @var{zz}] =} meshgrid (@var{x}, @var{y}, @var{z}) |
5378 | 21 ## @deftypefnx {Function File} {[@var{xx}, @var{yy}] =} meshgrid (@var{x}, @var{y}) |
3439 | 22 ## @deftypefnx {Function File} {[@var{xx}, @var{yy}] =} meshgrid (@var{x}) |
5717 | 23 ## 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
|
24 ## returning 3 arguments, return three-dimensional arrays corresponding |
5717 | 25 ## to the @var{x}, @var{y}, and @var{z} coordinates of a mesh. When |
26 ## returning only 2 arguments, return matrices corresponding to the | |
27 ## @var{x} and @var{y} coordinates of a mesh. The rows of @var{xx} are | |
28 ## copies of @var{x}, and the columns of @var{yy} are copies of @var{y}. | |
29 ## If @var{y} is omitted, then it is assumed to be the same as @var{x}, | |
30 ## and @var{z} is assumed the same as @var{y}. | |
5642 | 31 ## @seealso{mesh, contour} |
3407 | 32 ## @end deftypefn |
1713 | 33 |
2314 | 34 ## Author: jwe |
35 | |
5378 | 36 function [xx, yy, zz] = meshgrid (x, y, z) |
1713 | 37 |
5717 | 38 if (nargin == 0 || nargin > 3) |
6046 | 39 print_usage (); |
5717 | 40 endif |
41 | |
42 if (nargin < 2) | |
1713 | 43 y = x; |
44 endif | |
5717 | 45 |
6813 | 46 ## Use repmat to ensure that the result values have the same type as |
47 ## the arguments. | |
48 | |
5717 | 49 if (nargout < 3) |
4030 | 50 if (isvector (x) && isvector (y)) |
6813 | 51 xx = repmat (x(:).', length (y), 1); |
52 yy = repmat (y(:), 1, length (x)); | |
1713 | 53 else |
54 error ("meshgrid: arguments must be vectors"); | |
55 endif | |
56 else | |
5717 | 57 if (nargin < 3) |
58 z = y; | |
59 endif | |
60 if (isvector (x) && isvector (y) && isvector (z)) | |
61 lenx = length (x); | |
62 leny = length (y); | |
63 lenz = length (z); | |
6813 | 64 xx = repmat (repmat (x(:).', leny, 1), [1, 1, lenz]); |
65 yy = repmat (repmat (y(:), 1, lenx), [1, 1, lenz]); | |
5717 | 66 zz = reshape (repmat (z(:).', lenx*leny, 1)(:), leny, lenx, lenz); |
67 else | |
6813 | 68 error ("meshgrid: arguments must be vectors"); |
5717 | 69 endif |
1713 | 70 endif |
71 | |
72 endfunction | |
13263
a156263b5509
Add tests for meshgrid and ndgrid.
Kai Habel <kai.habel@gmx.de>
parents:
11523
diff
changeset
|
73 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
74 |
13263
a156263b5509
Add tests for meshgrid and ndgrid.
Kai Habel <kai.habel@gmx.de>
parents:
11523
diff
changeset
|
75 %!test |
a156263b5509
Add tests for meshgrid and ndgrid.
Kai Habel <kai.habel@gmx.de>
parents:
11523
diff
changeset
|
76 %! x = 1:2; |
a156263b5509
Add tests for meshgrid and ndgrid.
Kai Habel <kai.habel@gmx.de>
parents:
11523
diff
changeset
|
77 %! y = 1:3; |
a156263b5509
Add tests for meshgrid and ndgrid.
Kai Habel <kai.habel@gmx.de>
parents:
11523
diff
changeset
|
78 %! z = 1:4; |
a156263b5509
Add tests for meshgrid and ndgrid.
Kai Habel <kai.habel@gmx.de>
parents:
11523
diff
changeset
|
79 %! [XX, YY, ZZ] = meshgrid (x, y, z); |
a156263b5509
Add tests for meshgrid and ndgrid.
Kai Habel <kai.habel@gmx.de>
parents:
11523
diff
changeset
|
80 %! assert (size_equal (XX, YY, ZZ)); |
a156263b5509
Add tests for meshgrid and ndgrid.
Kai Habel <kai.habel@gmx.de>
parents:
11523
diff
changeset
|
81 %! assert (ndims (XX), 3); |
a156263b5509
Add tests for meshgrid and ndgrid.
Kai Habel <kai.habel@gmx.de>
parents:
11523
diff
changeset
|
82 %! assert (size (XX), [3, 2, 4]); |
a156263b5509
Add tests for meshgrid and ndgrid.
Kai Habel <kai.habel@gmx.de>
parents:
11523
diff
changeset
|
83 %! assert (XX(1) * YY(1) * ZZ(1), x(1) * y(1) * z(1)); |
a156263b5509
Add tests for meshgrid and ndgrid.
Kai Habel <kai.habel@gmx.de>
parents:
11523
diff
changeset
|
84 %! assert (XX(end) * YY(end) * ZZ(end), x(end) * y(end) * z(end)); |
a156263b5509
Add tests for meshgrid and ndgrid.
Kai Habel <kai.habel@gmx.de>
parents:
11523
diff
changeset
|
85 |
a156263b5509
Add tests for meshgrid and ndgrid.
Kai Habel <kai.habel@gmx.de>
parents:
11523
diff
changeset
|
86 %!test |
a156263b5509
Add tests for meshgrid and ndgrid.
Kai Habel <kai.habel@gmx.de>
parents:
11523
diff
changeset
|
87 %! x = 1:2; |
a156263b5509
Add tests for meshgrid and ndgrid.
Kai Habel <kai.habel@gmx.de>
parents:
11523
diff
changeset
|
88 %! y = 1:3; |
a156263b5509
Add tests for meshgrid and ndgrid.
Kai Habel <kai.habel@gmx.de>
parents:
11523
diff
changeset
|
89 %! [XX, YY] = meshgrid (x, y); |
a156263b5509
Add tests for meshgrid and ndgrid.
Kai Habel <kai.habel@gmx.de>
parents:
11523
diff
changeset
|
90 %! assert (size_equal (XX, YY)); |
a156263b5509
Add tests for meshgrid and ndgrid.
Kai Habel <kai.habel@gmx.de>
parents:
11523
diff
changeset
|
91 %! assert (ndims (XX), 2); |
a156263b5509
Add tests for meshgrid and ndgrid.
Kai Habel <kai.habel@gmx.de>
parents:
11523
diff
changeset
|
92 %! assert (size (XX), [3, 2]); |
a156263b5509
Add tests for meshgrid and ndgrid.
Kai Habel <kai.habel@gmx.de>
parents:
11523
diff
changeset
|
93 %! assert (XX(1) * YY(1), x(1) * y(1)); |
a156263b5509
Add tests for meshgrid and ndgrid.
Kai Habel <kai.habel@gmx.de>
parents:
11523
diff
changeset
|
94 %! assert (XX(end) * YY(end), x(end) * y(end)); |
a156263b5509
Add tests for meshgrid and ndgrid.
Kai Habel <kai.habel@gmx.de>
parents:
11523
diff
changeset
|
95 |
a156263b5509
Add tests for meshgrid and ndgrid.
Kai Habel <kai.habel@gmx.de>
parents:
11523
diff
changeset
|
96 %!test |
a156263b5509
Add tests for meshgrid and ndgrid.
Kai Habel <kai.habel@gmx.de>
parents:
11523
diff
changeset
|
97 %! x = 1:3; |
a156263b5509
Add tests for meshgrid and ndgrid.
Kai Habel <kai.habel@gmx.de>
parents:
11523
diff
changeset
|
98 %! [XX1, YY1] = meshgrid (x, x); |
a156263b5509
Add tests for meshgrid and ndgrid.
Kai Habel <kai.habel@gmx.de>
parents:
11523
diff
changeset
|
99 %! [XX2, YY2] = meshgrid (x); |
a156263b5509
Add tests for meshgrid and ndgrid.
Kai Habel <kai.habel@gmx.de>
parents:
11523
diff
changeset
|
100 %! assert (size_equal (XX1, XX2, YY1, YY2)); |
a156263b5509
Add tests for meshgrid and ndgrid.
Kai Habel <kai.habel@gmx.de>
parents:
11523
diff
changeset
|
101 %! assert (ndims (XX1), 2); |
a156263b5509
Add tests for meshgrid and ndgrid.
Kai Habel <kai.habel@gmx.de>
parents:
11523
diff
changeset
|
102 %! assert (size (XX1), [3, 3]); |
a156263b5509
Add tests for meshgrid and ndgrid.
Kai Habel <kai.habel@gmx.de>
parents:
11523
diff
changeset
|
103 %! assert (XX1, XX2); |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
104 %! assert (YY1, YY2); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
105 |