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