wolffd@0: function C = myunion(A,B) wolffd@0: % MYUNION Union of two sets of positive integers (much faster than built-in union) wolffd@0: % C = myunion(A,B) wolffd@0: wolffd@0: if isempty(A) wolffd@0: ma = 0; wolffd@0: else wolffd@0: ma = max(A); wolffd@0: end wolffd@0: wolffd@0: if isempty(B) wolffd@0: mb = 0; wolffd@0: else wolffd@0: mb = max(B); wolffd@0: end wolffd@0: wolffd@0: if ma==0 & mb==0 wolffd@0: C = []; wolffd@0: elseif ma==0 & mb>0 wolffd@0: C = B; wolffd@0: elseif ma>0 & mb==0 wolffd@0: C = A; wolffd@0: else wolffd@0: %bits = sparse(1, max(ma,mb)); wolffd@0: bits = zeros(1, max(ma,mb)); wolffd@0: bits(A) = 1; wolffd@0: bits(B) = 1; wolffd@0: C = find(bits); wolffd@0: end