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