diff scripts/set/intersect.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 ef95b930f1cf
children 95c3e38098bf
line wrap: on
line diff
--- a/scripts/set/intersect.m
+++ b/scripts/set/intersect.m
@@ -24,6 +24,7 @@
 ## Return the elements in both @var{a} and @var{b}, sorted in ascending
 ## order.  If @var{a} and @var{b} are both column vectors return a column
 ## vector, otherwise return a row vector.
+## @var{a}, @var{b} may be cell arrays of string(s).
 ##
 ## Return index vectors @var{ia} and @var{ib} such that @code{a(ia)==c} and
 ## @code{b(ib)==c}.
@@ -37,10 +38,7 @@
     print_usage ();
   endif
 
-  if (nargin == 3 && ! strcmpi (varargin{1}, "rows"))
-    error ("intersect: if a third input argument is present, it must be the string 'rows'");
-  endif
-
+  [a, b] = validargs ("intersect", a, b, varargin{:});
 
   if (isempty (a) || isempty (b))
     c = ia = ib = [];
@@ -70,13 +68,11 @@
       c = c(ii);
     endif
 
-
     if (nargout > 1)
       ia = ja(ic(ii));                  ## a(ia) == c
       ib = jb(ic(ii+1) - length (a));   ## b(ib) == c
     endif
 
-
     if (nargin == 2 && (size (b, 1) == 1 || size (a, 1) == 1))
       c = c.';
     endif