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