Mercurial > hg > camir-aes2014
comparison 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 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e9a9cd732c1e |
---|---|
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 |