comparison scripts/set/setxor.m @ 10088:5edee330d4cb

better argument checking and handling in set functions
author Jaroslav Hajek <highegg@gmail.com>
date Tue, 12 Jan 2010 16:50:25 +0100
parents 0bcfeadb6178
children 95c3e38098bf
comparison
equal deleted inserted replaced
10087:090173f2db40 10088:5edee330d4cb
22 ## @deftypefnx {Function File} {} setxor (@var{a}, @var{b}, 'rows') 22 ## @deftypefnx {Function File} {} setxor (@var{a}, @var{b}, 'rows')
23 ## 23 ##
24 ## Return the elements exclusive to @var{a} or @var{b}, sorted in ascending 24 ## Return the elements exclusive to @var{a} or @var{b}, sorted in ascending
25 ## order. If @var{a} and @var{b} are both column vectors return a column 25 ## order. If @var{a} and @var{b} are both column vectors return a column
26 ## vector, otherwise return a row vector. 26 ## vector, otherwise return a row vector.
27 ## @var{a}, @var{b} may be cell arrays of string(s).
27 ## 28 ##
28 ## @deftypefnx {Function File} {[@var{c}, @var{ia}, @var{ib}] =} setxor (@var{a}, @var{b}) 29 ## @deftypefnx {Function File} {[@var{c}, @var{ia}, @var{ib}] =} setxor (@var{a}, @var{b})
29 ## 30 ##
30 ## Return index vectors @var{ia} and @var{ib} such that @code{a(ia)} and @code{b(ib)} are 31 ## Return index vectors @var{ia} and @var{ib} such that @code{a(ia)} and @code{b(ib)} are
31 ## disjoint sets whose union is @var{c}. 32 ## disjoint sets whose union is @var{c}.
37 38
38 if (nargin < 2 || nargin > 3) 39 if (nargin < 2 || nargin > 3)
39 print_usage (); 40 print_usage ();
40 endif 41 endif
41 42
42 if (nargin == 3 && ! strcmpi (varargin{1}, "rows")) 43 [a, b] = validargs ("setxor", a, b, varargin{:});
43 error ("setxor: if a third input argument is present, it must be the string 'rows'");
44 endif
45 44
46 ## Form A and B into sets. 45 ## Form A and B into sets.
47 if (nargout > 1) 46 if (nargout > 1)
48 [a, ia] = unique (a, varargin{:}); 47 [a, ia] = unique (a, varargin{:});
49 [b, ib] = unique (b, varargin{:}); 48 [b, ib] = unique (b, varargin{:});