diff scripts/set/setdiff.m @ 6386:5a91bf0a47e8

[project @ 2007-03-07 05:56:43 by jwe]
author jwe
date Wed, 07 Mar 2007 05:56:43 +0000 (2007-03-07)
parents a192de8c0ead
children 93c65f2a5668
line wrap: on
line diff
--- a/scripts/set/setdiff.m
+++ b/scripts/set/setdiff.m
@@ -57,8 +57,8 @@
       b = unique (b, "rows");
       [dummy, idx] = sortrows ([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))), :) = [];
+      dups = find (all (dummy(1:end-1,:) == dummy(2:end,:), 2));
+      c(idx(dups),:) = [];
     endif
   else
     c = unique (a);
@@ -67,12 +67,12 @@
       b = unique (b);
       [dummy, idx] = sort ([c(:); b(:)]);
       ## Eliminate those elements of a that are the same as in b.
-      n = length (dummy);
       if (iscellstr (dummy))
-	c(idx(find (strcmp (dummy(1:n-1), dummy(2:n))))) = [];
+        dups = find (strcmp (dummy(1:end-1), dummy(2:end)));
       else
-	c(idx(find (dummy(1:n-1) == dummy(2:n)))) = [];
+	dups = find (dummy(1:end-1) == dummy(2:end));
       endif
+      c(idx(dups)) = [];
       ## Reshape if necessary.
       if (size (c, 1) != 1 && size (b, 1) == 1)
 	c = c.';
@@ -87,5 +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([1, 2; 3, 4], [1, 2; 3, 6], "rows"), [3, 4])
 %!assert(setdiff({"one","two";"three","four"},{"one","two";"three","six"}), {"four"})