Mercurial > hg > octave-lyh
annotate scripts/set/setxor.m @ 14359:7277fe922e99
doc: Use Octave preference for double quote in docstrings in scripts/
* interp1.m, interp2.m, interp3.m, interpn.m, profexplore.m, profile.m,
profshow.m, quadgk.m, lookfor.m, imagesc.m, bzip2.m, gzip.m, parseparams.m,
pkg.m, ancestor.m, caxis.m, ezmesh.m, ezmeshc.m, ezsurf.m, ezsurfc.m, hidden.m,
hold.m, patch.m, pie.m, pie3.m, quiver.m, quiver3.m, scatter3.m,
uicontextmenu.m, uicontrol.m, uipanel.m, uipushtool.m, uitoggletool.m,
uitoolbar.m, xlim.m, ylim.m, zlim.m, ismember.m, setxor.m, filter2.m, bicg.m,
demo.m, example.m, fail.m, test.m: Use Octave preference for double quote in
docstrings in scripts/ directory.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Mon, 13 Feb 2012 07:38:23 -0800 |
parents | 72c96de7a403 |
children | f3d52523cde1 |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
1 ## Copyright (C) 2008-2012 Jaroslav Hajek |
11523 | 2 ## Copyright (C) 2000, 2006-2007 Paul Kienzle |
5825 | 3 ## |
4 ## This file is part of Octave. | |
5 ## | |
6 ## Octave is free software; you can redistribute it and/or modify it | |
12849
e0a58c741996
codesprint: Reformat setxor's docstring
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11587
diff
changeset
|
7 ## under the terms of the GNU General Public License as published by the |
e0a58c741996
codesprint: Reformat setxor's docstring
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11587
diff
changeset
|
8 ## Free Software Foundation; either version 3 of the License, or (at |
7016 | 9 ## your option) any later version. |
5825 | 10 ## |
12849
e0a58c741996
codesprint: Reformat setxor's docstring
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11587
diff
changeset
|
11 ## Octave is distributed in the hope that it will be useful, but WITHOUT |
e0a58c741996
codesprint: Reformat setxor's docstring
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11587
diff
changeset
|
12 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
e0a58c741996
codesprint: Reformat setxor's docstring
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11587
diff
changeset
|
13 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
e0a58c741996
codesprint: Reformat setxor's docstring
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11587
diff
changeset
|
14 ## for more details. |
5825 | 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/>. | |
5825 | 19 |
20 ## -*- texinfo -*- | |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
21 ## @deftypefn {Function File} {} setxor (@var{a}, @var{b}) |
14359
7277fe922e99
doc: Use Octave preference for double quote in docstrings in scripts/
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
22 ## @deftypefnx {Function File} {} setxor (@var{a}, @var{b}, "rows") |
12849
e0a58c741996
codesprint: Reformat setxor's docstring
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11587
diff
changeset
|
23 ## @deftypefnx {Function File} {[@var{c}, @var{ia}, @var{ib}] =} setxor (@var{a}, @var{b}) |
5825 | 24 ## |
25 ## Return the elements exclusive to @var{a} or @var{b}, sorted in ascending | |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
26 ## order. If @var{a} and @var{b} are both column vectors return a column |
5825 | 27 ## vector, otherwise return a row vector. |
10088
5edee330d4cb
better argument checking and handling in set functions
Jaroslav Hajek <highegg@gmail.com>
parents:
9659
diff
changeset
|
28 ## @var{a}, @var{b} may be cell arrays of string(s). |
5825 | 29 ## |
12849
e0a58c741996
codesprint: Reformat setxor's docstring
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11587
diff
changeset
|
30 ## With three output arguments, return index vectors @var{ia} and @var{ib} |
e0a58c741996
codesprint: Reformat setxor's docstring
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11587
diff
changeset
|
31 ## such that @code{a(ia)} and @code{b(ib)} are disjoint sets whose union |
e0a58c741996
codesprint: Reformat setxor's docstring
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11587
diff
changeset
|
32 ## is @var{c}. |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
33 ## |
5825 | 34 ## @seealso{unique, union, intersect, setdiff, ismember} |
35 ## @end deftypefn | |
36 | |
7920
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
37 function [c, ia, ib] = setxor (a, b, varargin) |
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
38 |
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
39 if (nargin < 2 || nargin > 3) |
6046 | 40 print_usage (); |
5825 | 41 endif |
42 | |
10088
5edee330d4cb
better argument checking and handling in set functions
Jaroslav Hajek <highegg@gmail.com>
parents:
9659
diff
changeset
|
43 [a, b] = validargs ("setxor", a, b, varargin{:}); |
7920
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
44 |
5825 | 45 ## Form A and B into sets. |
7920
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
46 if (nargout > 1) |
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
47 [a, ia] = unique (a, varargin{:}); |
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
48 [b, ib] = unique (b, varargin{:}); |
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
49 else |
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
50 a = unique (a, varargin{:}); |
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
51 b = unique (b, varargin{:}); |
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
52 endif |
5825 | 53 |
54 if (isempty (a)) | |
55 c = b; | |
56 elseif (isempty (b)) | |
57 c = a; | |
58 else | |
59 ## Reject duplicates. | |
7920
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
60 if (nargin > 2) |
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
61 na = rows (a); nb = rows (b); |
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
62 [c, i] = sortrows ([a; b]); |
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
63 n = rows (c); |
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
64 idx = find (all (c(1:n-1) == c(2:n), 2)); |
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
65 if (! isempty (idx)) |
10549 | 66 c([idx, idx+1],:) = []; |
67 i([idx, idx+1],:) = []; | |
7920
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
68 endif |
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
69 else |
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
70 na = numel (a); nb = numel (b); |
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
71 [c, i] = sort ([a(:); b(:)]); |
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
72 n = length (c); |
9481
a3ae7abaf659
support cellstrs in setxor
Pieter Eendebak <pieter.eendebak@gmail.com>
parents:
9051
diff
changeset
|
73 if (iscell (c)) |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
74 idx = find (strcmp (c(1:n-1), c(2:n))); |
9481
a3ae7abaf659
support cellstrs in setxor
Pieter Eendebak <pieter.eendebak@gmail.com>
parents:
9051
diff
changeset
|
75 else |
a3ae7abaf659
support cellstrs in setxor
Pieter Eendebak <pieter.eendebak@gmail.com>
parents:
9051
diff
changeset
|
76 idx = find (c(1:n-1) == c(2:n)); |
a3ae7abaf659
support cellstrs in setxor
Pieter Eendebak <pieter.eendebak@gmail.com>
parents:
9051
diff
changeset
|
77 endif |
7920
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
78 if (! isempty (idx)) |
10549 | 79 c([idx, idx+1]) = []; |
80 i([idx, idx+1]) = []; | |
7920
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
81 endif |
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
82 if (size (a, 1) == 1 || size (b, 1) == 1) |
10549 | 83 c = c.'; |
7920
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
84 endif |
5825 | 85 endif |
86 endif | |
7920
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
87 if (nargout > 1) |
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
88 ia = ia(i(i <= na)); |
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
89 ib = ib(i(i > na) - na); |
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
90 endif |
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
91 |
5825 | 92 endfunction |
93 | |
94 %!assert(setxor([1,2,3],[2,3,4]),[1,4]) | |
9498
f7cc8f30f3b8
Added test for setxor
Pieter Eendebak <pieter.eendebak@gmail.com>
parents:
9481
diff
changeset
|
95 %!assert(setxor({'a'}, {'a', 'b'}), {'b'}); |
7920
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
96 %!test |
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
97 %! a = [3, 1, 4, 1, 5]; b = [1, 2, 3, 4]; |
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
98 %! [y, ia, ib] = setxor (a, b.'); |
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
99 %! assert(y, [2, 5]); |
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
100 %! assert(y, sort([a(ia), b(ib)])); |
9498
f7cc8f30f3b8
Added test for setxor
Pieter Eendebak <pieter.eendebak@gmail.com>
parents:
9481
diff
changeset
|
101 |