Daniel@0: function [B, keep] = approx_unique(A, thresh, flag) Daniel@0: % APPROX_UNIQUE Return elements of A that differ from the rest by less than thresh Daniel@0: % B = approx_unique(A, thresh) Daniel@0: % B = approx_unique(A, thresh, 'rows') Daniel@0: Daniel@0: keep = []; Daniel@0: Daniel@0: if nargin < 3 | isempty(flag) Daniel@0: A = sort(A) Daniel@0: B = A(1); Daniel@0: for i=2:length(A) Daniel@0: if ~approxeq(A(i), A(i-1), thresh) Daniel@0: B = [B A(i)]; Daniel@0: keep = [keep i]; Daniel@0: end Daniel@0: end Daniel@0: else Daniel@0: % A = sortrows(A); Daniel@0: % B = A(1,:); Daniel@0: % for i=2:size(A,1) Daniel@0: % if ~approxeq(A(i,:), A(i-1,:), thresh) Daniel@0: % B = [B; A(i,:)]; Daniel@0: % keep = [keep i]; Daniel@0: % end Daniel@0: % end Daniel@0: B = []; Daniel@0: for i=1:size(A,1) Daniel@0: duplicate = 0; Daniel@0: for j=i+1:size(A,1) Daniel@0: if approxeq(A(i,:), A(j,:), thresh) Daniel@0: duplicate = 1; Daniel@0: break; Daniel@0: end Daniel@0: end Daniel@0: if ~duplicate Daniel@0: B = [B; A(i,:)]; Daniel@0: keep = [keep i]; Daniel@0: end Daniel@0: end Daniel@0: end Daniel@0: