annotate toolboxes/FullBNT-1.0.7/KPMtools/mysetdiff.m @ 0:cc4b1211e677 tip

initial commit to HG from Changeset: 646 (e263d8a21543) added further path and more save "camirversion.m"
author Daniel Wolff
date Fri, 19 Aug 2016 13:07:06 +0200
parents
children
rev   line source
Daniel@0 1 function C = mysetdiff(A,B)
Daniel@0 2 % MYSETDIFF Set difference of two sets of positive integers (much faster than built-in setdiff)
Daniel@0 3 % C = mysetdiff(A,B)
Daniel@0 4 % C = A \ B = { things in A that are not in B }
Daniel@0 5 %
Daniel@0 6 % Original by Kevin Murphy, modified by Leon Peshkin
Daniel@0 7
Daniel@0 8 if isempty(A)
Daniel@0 9 C = [];
Daniel@0 10 return;
Daniel@0 11 elseif isempty(B)
Daniel@0 12 C = A;
Daniel@0 13 return;
Daniel@0 14 else % both non-empty
Daniel@0 15 bits = zeros(1, max(max(A), max(B)));
Daniel@0 16 bits(A) = 1;
Daniel@0 17 bits(B) = 0;
Daniel@0 18 C = A(logical(bits(A)));
Daniel@0 19 end