Mercurial > hg > octave-lyh
annotate scripts/set/union.m @ 16508:f19e24c97b20
move common warndlg, errordlg, helpdlg, and msgbox code to private function
* message_dialog.m: New file.
* scripts/ui/module.mk: Include it in the list of functions.
* errordlg.m, helpdlg.m, warndlg.m, msgbox.m: Call message_dialog to
do most of the work.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 12 Apr 2013 18:17:26 -0400 |
parents | b10a23fe80bb |
children | bc924baa2c4e |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
11587
diff
changeset
|
1 ## Copyright (C) 1994-2012 John W. Eaton |
11523 | 2 ## Copyright (C) 2008-2009 Jaroslav Hajek |
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/>. | |
2303 | 19 |
3368 | 20 ## -*- texinfo -*- |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10712
diff
changeset
|
21 ## @deftypefn {Function File} {} union (@var{a}, @var{b}) |
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10712
diff
changeset
|
22 ## @deftypefnx {Function File} {} union (@var{a}, @var{b}, "rows") |
16489
36dba9be680b
doc: Make documentation compatible with Texinfo 5.0 (bug #38392)
Amod Mulay <amodmulay1@gmail.com>
parents:
14872
diff
changeset
|
23 ## @deftypefnx {Function File} {[@var{c}, @var{ia}, @var{ib}] =} union (@var{a}, @var{b}) |
36dba9be680b
doc: Make documentation compatible with Texinfo 5.0 (bug #38392)
Amod Mulay <amodmulay1@gmail.com>
parents:
14872
diff
changeset
|
24 ## |
7920
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7411
diff
changeset
|
25 ## Return the set of elements that are in either of the sets @var{a} and |
16491
b10a23fe80bb
doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
Rik <rik@octave.org>
parents:
16489
diff
changeset
|
26 ## @var{b}. @var{a}, @var{b} may be cell arrays of strings. |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
27 ## For example: |
3426 | 28 ## |
3368 | 29 ## @example |
30 ## @group | |
7344 | 31 ## union ([1, 2, 4], [2, 3, 5]) |
14327
4d917a6a858b
doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
32 ## @result{} [1, 2, 3, 4, 5] |
7344 | 33 ## @end group |
34 ## @end example | |
35 ## | |
16491
b10a23fe80bb
doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
Rik <rik@octave.org>
parents:
16489
diff
changeset
|
36 ## If the optional third input argument is the string "rows" then each row of |
b10a23fe80bb
doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
Rik <rik@octave.org>
parents:
16489
diff
changeset
|
37 ## the matrices @var{a} and @var{b} will be considered as a single set element. |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
38 ## For example: |
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
39 ## |
7344 | 40 ## @example |
41 ## @group | |
14327
4d917a6a858b
doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
42 ## union ([1, 2; 2, 3], [1, 2; 3, 4], "rows") |
4d917a6a858b
doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
43 ## @result{} 1 2 |
4d917a6a858b
doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
44 ## 2 3 |
4d917a6a858b
doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
45 ## 3 4 |
3368 | 46 ## @end group |
47 ## @end example | |
7920
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7411
diff
changeset
|
48 ## |
16491
b10a23fe80bb
doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
Rik <rik@octave.org>
parents:
16489
diff
changeset
|
49 ## The optional outputs @var{ia} and @var{ib} are index vectors such that |
b10a23fe80bb
doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
Rik <rik@octave.org>
parents:
16489
diff
changeset
|
50 ## @code{a(ia)} and @code{b(ib)} are disjoint sets whose union is @var{c}. |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
51 ## |
10712
6a5a0c9df5d7
union.m: Remove seealso reference to deprecated function.
Rik <octave@nomad.inbox5.com>
parents:
10711
diff
changeset
|
52 ## @seealso{intersect, setdiff, unique} |
3406 | 53 ## @end deftypefn |
3368 | 54 |
2314 | 55 ## Author: jwe |
56 | |
7920
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7411
diff
changeset
|
57 function [y, ia, ib] = union (a, b, varargin) |
559 | 58 |
7344 | 59 if (nargin < 2 || nargin > 3) |
6046 | 60 print_usage (); |
559 | 61 endif |
62 | |
10088
5edee330d4cb
better argument checking and handling in set functions
Jaroslav Hajek <highegg@gmail.com>
parents:
9659
diff
changeset
|
63 [a, b] = validargs ("union", a, b, varargin{:}); |
7344 | 64 |
7920
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7411
diff
changeset
|
65 if (nargin == 2) |
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7411
diff
changeset
|
66 y = [a(:); b(:)]; |
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7411
diff
changeset
|
67 na = numel (a); nb = numel (b); |
14872
c2dbdeaa25df
maint: use rows() and columns() to clarify m-files.
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
68 if (rows (a) == 1 || rows (b) == 1) |
7920
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7411
diff
changeset
|
69 y = y.'; |
4317 | 70 endif |
10088
5edee330d4cb
better argument checking and handling in set functions
Jaroslav Hajek <highegg@gmail.com>
parents:
9659
diff
changeset
|
71 else |
7920
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7411
diff
changeset
|
72 y = [a; b]; |
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7411
diff
changeset
|
73 na = rows (a); nb = rows (b); |
559 | 74 endif |
75 | |
7920
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7411
diff
changeset
|
76 if (nargout == 1) |
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7411
diff
changeset
|
77 y = unique (y, varargin{:}); |
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7411
diff
changeset
|
78 else |
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7411
diff
changeset
|
79 [y, i] = unique (y, varargin{:}); |
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7411
diff
changeset
|
80 ia = i(i <= na); |
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7411
diff
changeset
|
81 ib = i(i > na) - na; |
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7411
diff
changeset
|
82 endif |
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7411
diff
changeset
|
83 |
559 | 84 endfunction |
7411 | 85 |
86 | |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
87 %!assert (union ([1, 2, 4], [2, 3, 5]), [1, 2, 3, 4, 5]); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
88 %!assert (union ([1; 2; 4], [2, 3, 5]), [1, 2, 3, 4, 5]); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
89 %!assert (union ([1, 2, 3], [5; 7; 9]), [1, 2, 3, 5, 7, 9]); |
7411 | 90 |
7920
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7411
diff
changeset
|
91 %!test |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
92 %! a = [3, 1, 4, 1, 5]; b = [1, 2, 3, 4]; |
7920
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7411
diff
changeset
|
93 %! [y, ia, ib] = union (a, b.'); |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
94 %! assert (y, [1, 2, 3, 4, 5]); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
95 %! assert (y, sort ([a(ia), b(ib)])); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
96 |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
97 %!error union (1) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
98 %!error union (1, 2, 3) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
99 |