matthiasm@8: function C = mysetdiff(A,B) matthiasm@8: % MYSETDIFF Set difference of two sets of positive integers (much faster than built-in setdiff) matthiasm@8: % C = mysetdiff(A,B) matthiasm@8: % C = A \ B = { things in A that are not in B } matthiasm@8: % matthiasm@8: % Original by Kevin Murphy, modified by Leon Peshkin matthiasm@8: matthiasm@8: if isempty(A) matthiasm@8: C = []; matthiasm@8: return; matthiasm@8: elseif isempty(B) matthiasm@8: C = A; matthiasm@8: return; matthiasm@8: else % both non-empty matthiasm@8: bits = zeros(1, max(max(A), max(B))); matthiasm@8: bits(A) = 1; matthiasm@8: bits(B) = 0; matthiasm@8: C = A(logical(bits(A))); matthiasm@8: end