Mercurial > hg > camir-aes2014
annotate toolboxes/FullBNT-1.0.7/KPMtools/mysetdiff.m @ 0:e9a9cd732c1e tip
first hg version after svn
author | wolffd |
---|---|
date | Tue, 10 Feb 2015 15:05:51 +0000 |
parents | |
children |
rev | line source |
---|---|
wolffd@0 | 1 function C = mysetdiff(A,B) |
wolffd@0 | 2 % MYSETDIFF Set difference of two sets of positive integers (much faster than built-in setdiff) |
wolffd@0 | 3 % C = mysetdiff(A,B) |
wolffd@0 | 4 % C = A \ B = { things in A that are not in B } |
wolffd@0 | 5 % |
wolffd@0 | 6 % Original by Kevin Murphy, modified by Leon Peshkin |
wolffd@0 | 7 |
wolffd@0 | 8 if isempty(A) |
wolffd@0 | 9 C = []; |
wolffd@0 | 10 return; |
wolffd@0 | 11 elseif isempty(B) |
wolffd@0 | 12 C = A; |
wolffd@0 | 13 return; |
wolffd@0 | 14 else % both non-empty |
wolffd@0 | 15 bits = zeros(1, max(max(A), max(B))); |
wolffd@0 | 16 bits(A) = 1; |
wolffd@0 | 17 bits(B) = 0; |
wolffd@0 | 18 C = A(logical(bits(A))); |
wolffd@0 | 19 end |