comparison toolboxes/FullBNT-1.0.7/KPMtools/approx_unique.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 [B, keep] = approx_unique(A, thresh, flag)
2 % APPROX_UNIQUE Return elements of A that differ from the rest by less than thresh
3 % B = approx_unique(A, thresh)
4 % B = approx_unique(A, thresh, 'rows')
5
6 keep = [];
7
8 if nargin < 3 | isempty(flag)
9 A = sort(A)
10 B = A(1);
11 for i=2:length(A)
12 if ~approxeq(A(i), A(i-1), thresh)
13 B = [B A(i)];
14 keep = [keep i];
15 end
16 end
17 else
18 % A = sortrows(A);
19 % B = A(1,:);
20 % for i=2:size(A,1)
21 % if ~approxeq(A(i,:), A(i-1,:), thresh)
22 % B = [B; A(i,:)];
23 % keep = [keep i];
24 % end
25 % end
26 B = [];
27 for i=1:size(A,1)
28 duplicate = 0;
29 for j=i+1:size(A,1)
30 if approxeq(A(i,:), A(j,:), thresh)
31 duplicate = 1;
32 break;
33 end
34 end
35 if ~duplicate
36 B = [B; A(i,:)];
37 keep = [keep i];
38 end
39 end
40 end
41