annotate toolboxes/FullBNT-1.0.7/KPMtools/myunion.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 = myunion(A,B)
wolffd@0 2 % MYUNION Union of two sets of positive integers (much faster than built-in union)
wolffd@0 3 % C = myunion(A,B)
wolffd@0 4
wolffd@0 5 if isempty(A)
wolffd@0 6 ma = 0;
wolffd@0 7 else
wolffd@0 8 ma = max(A);
wolffd@0 9 end
wolffd@0 10
wolffd@0 11 if isempty(B)
wolffd@0 12 mb = 0;
wolffd@0 13 else
wolffd@0 14 mb = max(B);
wolffd@0 15 end
wolffd@0 16
wolffd@0 17 if ma==0 & mb==0
wolffd@0 18 C = [];
wolffd@0 19 elseif ma==0 & mb>0
wolffd@0 20 C = B;
wolffd@0 21 elseif ma>0 & mb==0
wolffd@0 22 C = A;
wolffd@0 23 else
wolffd@0 24 %bits = sparse(1, max(ma,mb));
wolffd@0 25 bits = zeros(1, max(ma,mb));
wolffd@0 26 bits(A) = 1;
wolffd@0 27 bits(B) = 1;
wolffd@0 28 C = find(bits);
wolffd@0 29 end