annotate scripts/set/setdiff.m @ 14872:c2dbdeaa25df

maint: use rows() and columns() to clarify m-files. * gradient.m, interp1q.m, rat.m, tsearchn.m, image.m, imwrite.m, area.m, contourc.m, hist.m, isocolors.m, isonormals.m, meshz.m, print.m, __bar__.m, __go_draw_axes__.m, __interp_cube__.m, __marching_cube__.m, __patch__.m, __print_parse_opts__.m, __quiver__.m, rose.m, shrinkfaces.m, stairs.m, surfnorm.m, tetramesh.m, text.m, deconv.m, spline.m, intersect.m, setdiff.m, setxor.m, union.m, periodogram.m, pcg.m, perms.m: Replace size (x,1) with rows (x) and size(x,2) with columns(x).
author Rik <octave@nomad.inbox5.com>
date Tue, 17 Jul 2012 13:34:19 -0700
parents f3d52523cde1
children bc924baa2c4e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14138
72c96de7a403 maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
1 ## Copyright (C) 2000-2012 Paul Kienzle
11523
fd0a3ac60b0e update copyright notices
John W. Eaton <jwe@octave.org>
parents: 10793
diff changeset
2 ## Copyright (C) 2008-2009 Jaroslav Hajek
5178
6758c11b5b99 [project @ 2005-03-03 05:18:04 by jwe]
jwe
parents:
diff changeset
3 ##
5181
41cd70503c72 [project @ 2005-03-03 05:49:55 by jwe]
jwe
parents: 5178
diff changeset
4 ## This file is part of Octave.
5178
6758c11b5b99 [project @ 2005-03-03 05:18:04 by jwe]
jwe
parents:
diff changeset
5 ##
5181
41cd70503c72 [project @ 2005-03-03 05:49:55 by jwe]
jwe
parents: 5178
diff changeset
6 ## Octave is free software; you can redistribute it and/or modify it
41cd70503c72 [project @ 2005-03-03 05:49:55 by jwe]
jwe
parents: 5178
diff changeset
7 ## under the terms of the GNU General Public License as published by
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6386
diff changeset
8 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6386
diff changeset
9 ## your option) any later version.
5181
41cd70503c72 [project @ 2005-03-03 05:49:55 by jwe]
jwe
parents: 5178
diff changeset
10 ##
41cd70503c72 [project @ 2005-03-03 05:49:55 by jwe]
jwe
parents: 5178
diff changeset
11 ## Octave is distributed in the hope that it will be useful, but
41cd70503c72 [project @ 2005-03-03 05:49:55 by jwe]
jwe
parents: 5178
diff changeset
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of
41cd70503c72 [project @ 2005-03-03 05:49:55 by jwe]
jwe
parents: 5178
diff changeset
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
41cd70503c72 [project @ 2005-03-03 05:49:55 by jwe]
jwe
parents: 5178
diff changeset
14 ## General Public License for more details.
5178
6758c11b5b99 [project @ 2005-03-03 05:18:04 by jwe]
jwe
parents:
diff changeset
15 ##
6758c11b5b99 [project @ 2005-03-03 05:18:04 by jwe]
jwe
parents:
diff changeset
16 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6386
diff changeset
17 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6386
diff changeset
18 ## <http://www.gnu.org/licenses/>.
5178
6758c11b5b99 [project @ 2005-03-03 05:18:04 by jwe]
jwe
parents:
diff changeset
19
6758c11b5b99 [project @ 2005-03-03 05:18:04 by jwe]
jwe
parents:
diff changeset
20 ## -*- texinfo -*-
10793
be55736a0783 Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
21 ## @deftypefn {Function File} {} setdiff (@var{a}, @var{b})
6248
7fad1fad19e1 [project @ 2007-01-22 17:28:17 by jwe]
jwe
parents: 6046
diff changeset
22 ## @deftypefnx {Function File} {} setdiff (@var{a}, @var{b}, "rows")
9051
1bf0ce0930be Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents: 7920
diff changeset
23 ## @deftypefnx {Function File} {[@var{c}, @var{i}] =} setdiff (@var{a}, @var{b})
5786
9c3c903f037e [project @ 2006-05-03 20:03:41 by jwe]
jwe
parents: 5642
diff changeset
24 ## Return the elements in @var{a} that are not in @var{b}, sorted in
5182
5b361aa47dff [project @ 2005-03-03 06:21:47 by jwe]
jwe
parents: 5181
diff changeset
25 ## ascending order. If @var{a} and @var{b} are both column vectors
5b361aa47dff [project @ 2005-03-03 06:21:47 by jwe]
jwe
parents: 5181
diff changeset
26 ## return a column vector, otherwise return a row vector.
10088
5edee330d4cb better argument checking and handling in set functions
Jaroslav Hajek <highegg@gmail.com>
parents: 9245
diff changeset
27 ## @var{a}, @var{b} may be cell arrays of string(s).
5786
9c3c903f037e [project @ 2006-05-03 20:03:41 by jwe]
jwe
parents: 5642
diff changeset
28 ##
9c3c903f037e [project @ 2006-05-03 20:03:41 by jwe]
jwe
parents: 5642
diff changeset
29 ## Given the optional third argument @samp{"rows"}, return the rows in
9c3c903f037e [project @ 2006-05-03 20:03:41 by jwe]
jwe
parents: 5642
diff changeset
30 ## @var{a} that are not in @var{b}, sorted in ascending order by rows.
7920
e56bb65186f6 improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 7017
diff changeset
31 ##
e56bb65186f6 improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 7017
diff changeset
32 ## If requested, return @var{i} such that @code{c = a(i)}.
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5307
diff changeset
33 ## @seealso{unique, union, intersect, setxor, ismember}
5178
6758c11b5b99 [project @ 2005-03-03 05:18:04 by jwe]
jwe
parents:
diff changeset
34 ## @end deftypefn
6758c11b5b99 [project @ 2005-03-03 05:18:04 by jwe]
jwe
parents:
diff changeset
35
5181
41cd70503c72 [project @ 2005-03-03 05:49:55 by jwe]
jwe
parents: 5178
diff changeset
36 ## Author: Paul Kienzle
41cd70503c72 [project @ 2005-03-03 05:49:55 by jwe]
jwe
parents: 5178
diff changeset
37 ## Adapted-by: jwe
41cd70503c72 [project @ 2005-03-03 05:49:55 by jwe]
jwe
parents: 5178
diff changeset
38
10088
5edee330d4cb better argument checking and handling in set functions
Jaroslav Hajek <highegg@gmail.com>
parents: 9245
diff changeset
39 function [c, i] = setdiff (a, b, varargin)
5786
9c3c903f037e [project @ 2006-05-03 20:03:41 by jwe]
jwe
parents: 5642
diff changeset
40
9c3c903f037e [project @ 2006-05-03 20:03:41 by jwe]
jwe
parents: 5642
diff changeset
41 if (nargin < 2 || nargin > 3)
6046
34f96dd5441b [project @ 2006-10-10 16:10:25 by jwe]
jwe
parents: 5967
diff changeset
42 print_usage ();
5786
9c3c903f037e [project @ 2006-05-03 20:03:41 by jwe]
jwe
parents: 5642
diff changeset
43 endif
5181
41cd70503c72 [project @ 2005-03-03 05:49:55 by jwe]
jwe
parents: 5178
diff changeset
44
10088
5edee330d4cb better argument checking and handling in set functions
Jaroslav Hajek <highegg@gmail.com>
parents: 9245
diff changeset
45 [a, b] = validargs ("setdiff", a, b, varargin{:});
6385
a192de8c0ead [project @ 2007-03-06 19:05:43 by jwe]
jwe
parents: 6248
diff changeset
46
10088
5edee330d4cb better argument checking and handling in set functions
Jaroslav Hajek <highegg@gmail.com>
parents: 9245
diff changeset
47 if (nargin > 2)
7920
e56bb65186f6 improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 7017
diff changeset
48 if (nargout > 1)
e56bb65186f6 improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 7017
diff changeset
49 [c, i] = unique (a, "rows");
e56bb65186f6 improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 7017
diff changeset
50 else
e56bb65186f6 improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 7017
diff changeset
51 c = unique (a, "rows");
e56bb65186f6 improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 7017
diff changeset
52 endif
5786
9c3c903f037e [project @ 2006-05-03 20:03:41 by jwe]
jwe
parents: 5642
diff changeset
53 if (! isempty (c) && ! isempty (b))
9c3c903f037e [project @ 2006-05-03 20:03:41 by jwe]
jwe
parents: 5642
diff changeset
54 ## Form a and b into combined set.
9c3c903f037e [project @ 2006-05-03 20:03:41 by jwe]
jwe
parents: 5642
diff changeset
55 b = unique (b, "rows");
9c3c903f037e [project @ 2006-05-03 20:03:41 by jwe]
jwe
parents: 5642
diff changeset
56 [dummy, idx] = sortrows ([c; b]);
9c3c903f037e [project @ 2006-05-03 20:03:41 by jwe]
jwe
parents: 5642
diff changeset
57 ## Eliminate those elements of a that are the same as in b.
6386
5a91bf0a47e8 [project @ 2007-03-07 05:56:43 by jwe]
jwe
parents: 6385
diff changeset
58 dups = find (all (dummy(1:end-1,:) == dummy(2:end,:), 2));
5a91bf0a47e8 [project @ 2007-03-07 05:56:43 by jwe]
jwe
parents: 6385
diff changeset
59 c(idx(dups),:) = [];
7920
e56bb65186f6 improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 7017
diff changeset
60 if (nargout > 1)
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10088
diff changeset
61 i(idx(dups),:) = [];
7920
e56bb65186f6 improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 7017
diff changeset
62 endif
5786
9c3c903f037e [project @ 2006-05-03 20:03:41 by jwe]
jwe
parents: 5642
diff changeset
63 endif
9c3c903f037e [project @ 2006-05-03 20:03:41 by jwe]
jwe
parents: 5642
diff changeset
64 else
7920
e56bb65186f6 improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 7017
diff changeset
65 if (nargout > 1)
e56bb65186f6 improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 7017
diff changeset
66 [c, i] = unique (a);
e56bb65186f6 improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 7017
diff changeset
67 else
e56bb65186f6 improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 7017
diff changeset
68 c = unique (a);
e56bb65186f6 improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 7017
diff changeset
69 endif
5786
9c3c903f037e [project @ 2006-05-03 20:03:41 by jwe]
jwe
parents: 5642
diff changeset
70 if (! isempty (c) && ! isempty (b))
9c3c903f037e [project @ 2006-05-03 20:03:41 by jwe]
jwe
parents: 5642
diff changeset
71 ## Form a and b into combined set.
9c3c903f037e [project @ 2006-05-03 20:03:41 by jwe]
jwe
parents: 5642
diff changeset
72 b = unique (b);
9c3c903f037e [project @ 2006-05-03 20:03:41 by jwe]
jwe
parents: 5642
diff changeset
73 [dummy, idx] = sort ([c(:); b(:)]);
9c3c903f037e [project @ 2006-05-03 20:03:41 by jwe]
jwe
parents: 5642
diff changeset
74 ## Eliminate those elements of a that are the same as in b.
6385
a192de8c0ead [project @ 2007-03-06 19:05:43 by jwe]
jwe
parents: 6248
diff changeset
75 if (iscellstr (dummy))
6386
5a91bf0a47e8 [project @ 2007-03-07 05:56:43 by jwe]
jwe
parents: 6385
diff changeset
76 dups = find (strcmp (dummy(1:end-1), dummy(2:end)));
6385
a192de8c0ead [project @ 2007-03-06 19:05:43 by jwe]
jwe
parents: 6248
diff changeset
77 else
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10088
diff changeset
78 dups = find (dummy(1:end-1) == dummy(2:end));
6385
a192de8c0ead [project @ 2007-03-06 19:05:43 by jwe]
jwe
parents: 6248
diff changeset
79 endif
6386
5a91bf0a47e8 [project @ 2007-03-07 05:56:43 by jwe]
jwe
parents: 6385
diff changeset
80 c(idx(dups)) = [];
7920
e56bb65186f6 improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 7017
diff changeset
81 if (nargout > 1)
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10088
diff changeset
82 i(idx(dups)) = [];
7920
e56bb65186f6 improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 7017
diff changeset
83 endif
5786
9c3c903f037e [project @ 2006-05-03 20:03:41 by jwe]
jwe
parents: 5642
diff changeset
84 ## Reshape if necessary.
14872
c2dbdeaa25df maint: use rows() and columns() to clarify m-files.
Rik <octave@nomad.inbox5.com>
parents: 14363
diff changeset
85 if (rows (c) != 1 && rows (b) == 1)
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10088
diff changeset
86 c = c.';
5786
9c3c903f037e [project @ 2006-05-03 20:03:41 by jwe]
jwe
parents: 5642
diff changeset
87 endif
5178
6758c11b5b99 [project @ 2005-03-03 05:18:04 by jwe]
jwe
parents:
diff changeset
88 endif
6758c11b5b99 [project @ 2005-03-03 05:18:04 by jwe]
jwe
parents:
diff changeset
89 endif
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
90
5178
6758c11b5b99 [project @ 2005-03-03 05:18:04 by jwe]
jwe
parents:
diff changeset
91 endfunction
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
92
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
93
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
94 %!assert (setdiff (["bb";"zz";"bb";"zz"], ["bb";"cc";"bb"], "rows"), "zz")
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
95 %!assert (setdiff (["b";"z";"b";"z"], ["b";"c";"b"], "rows"), "z")
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
96 %!assert (setdiff (["b";"z";"b";"z"], ["b";"c";"b"]), "z")
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
97 %!assert (setdiff ([1, 1; 2, 2; 3, 3; 4, 4], [1, 1; 2, 2; 4, 4], "rows"), [3 3])
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
98 %!assert (setdiff ([1; 2; 3; 4], [1; 2; 4], "rows"), 3)
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
99 %!assert (setdiff ([1, 2; 3, 4], [1, 2; 3, 6], "rows"), [3, 4])
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
100 %!assert (setdiff ({"one","two";"three","four"}, {"one","two";"three","six"}), {"four"})
7920
e56bb65186f6 improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 7017
diff changeset
101
e56bb65186f6 improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 7017
diff changeset
102 %!test
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
103 %! 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: 7017
diff changeset
104 %! [y, i] = setdiff (a, b.');
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
105 %! assert (y, [5]);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
106 %! assert (y, a(i));
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
107