diff --git a/scripts/set/setdiff.m b/scripts/set/setdiff.m --- a/scripts/set/setdiff.m +++ b/scripts/set/setdiff.m @@ -31,7 +31,7 @@ ## Author: Paul Kienzle ## Adapted-by: jwe -function c = setdiff (a, b, byrows_arg) +function [c,i] = setdiff (a, b, byrows_arg) if (nargin < 2 || nargin > 3) print_usage (); @@ -78,7 +78,13 @@ function c = setdiff (a, b, byrows_arg) endif endif endif - + + [sorta, idxa] = sort (a); + idx = idxa (find (all (repmat (sorta(:)',size(c,1)*size(c,2),1)-... + repmat (c(:), 1, size(a,1)*size(a,2))) == 0)); + [y,iy] = unique (a(idx)); + i = reshape (idx(iy), size(c,1), length(idx(iy))/size(c,1)); + endfunction %!assert(setdiff(["bb";"zz";"bb";"zz"],["bb";"cc";"bb"],"rows"), "zz")