changeset 6385:a192de8c0ead

[project @ 2007-03-06 19:05:43 by jwe]
author jwe
date Tue, 06 Mar 2007 19:05:43 +0000
parents c2eb95ca0e2b
children 5a91bf0a47e8
files scripts/ChangeLog scripts/set/setdiff.m
diffstat 2 files changed, 19 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/ChangeLog	Tue Mar 06 06:03:01 2007 +0000
+++ b/scripts/ChangeLog	Tue Mar 06 19:05:43 2007 +0000
@@ -1,3 +1,9 @@
+2007-03-06  David Bateman  <dbateman@free.fr>
+	    John W. Eaton  <jwe@octave.org>
+
+	* set/setdiff.m: Ignore "rows" for cell array args.
+	Handle cellstr args.
+
 2007-03-05  John W. Eaton  <jwe@octave.org>
 
 	* optimization/sqp.m: Defer first call to obj_hess until after
--- a/scripts/set/setdiff.m	Tue Mar 06 06:03:01 2007 +0000
+++ b/scripts/set/setdiff.m	Tue Mar 06 19:05:43 2007 +0000
@@ -32,20 +32,22 @@
 ## Author: Paul Kienzle
 ## Adapted-by: jwe
 
-function c = setdiff (a, b, byrows)
+function c = setdiff (a, b, byrows_arg)
 
   if (nargin < 2 || nargin > 3)
     print_usage ();
   endif
 
+  byrows = false;
+
   if (nargin == 3)
-    if (! strcmpi (byrows, "rows"))
+    if (! strcmpi (byrows_arg, "rows"))
       error ("expecting third argument to be \"rows\"");
+    elseif (iscell (a) || iscell (b))
+      warning ("setdiff: \"rows\" not valid for cell arrays");
     else
       byrows = true;
     endif
-  else
-    byrows = false;
   endif
 
   if (byrows)
@@ -66,7 +68,11 @@
       [dummy, idx] = sort ([c(:); b(:)]);
       ## Eliminate those elements of a that are the same as in b.
       n = length (dummy);
-      c(idx(find (dummy(1:n-1) == dummy(2:n)))) = [];
+      if (iscellstr (dummy))
+	c(idx(find (strcmp (dummy(1:n-1), dummy(2:n))))) = [];
+      else
+	c(idx(find (dummy(1:n-1) == dummy(2:n)))) = [];
+      endif
       ## Reshape if necessary.
       if (size (c, 1) != 1 && size (b, 1) == 1)
 	c = c.';
@@ -81,3 +87,5 @@
 %!assert(setdiff(["b";"z";"b";"z"],["b";"c";"b"]), "z")
 %!assert(setdiff([1, 1; 2, 2; 3, 3; 4, 4], [1, 1; 2, 2; 4, 4], "rows"), [3 3])
 %!assert(setdiff([1; 2; 3; 4], [1; 2; 4], "rows"), 3)
+%!assert(setdiff([1, 2; 3, 4], [1, 2; 3, 6], "rows"), [3, 6])
+%!assert(setdiff({"one","two";"three","four"},{"one","two";"three","six"}), {"four"})