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