www.gusucode.com > mbctools 工具箱 matlab 源码程序 > mbctools/@sweepset/uniqueFilters.m

    function [KeepFirst,KeepLast] = uniqueFilters(X,tol)
%UNIQUEFILTERS filters to keep unique points
%
% [KeepFirst,KeepLast] = uniqueFilters(X,tol)

%  Copyright 2008 The MathWorks, Inc. and Ford Global Technologies, Inc.

% get global data
Xg = double(X);
if nargin<2
    tol = 1e-3;
end

% Form logical matrix indicating nonunique points
[n,m] = size(Xg);
D = false(n);

% Range
R = max(Xg,[],1) - min(Xg,[],1);

for i=1:n
    if ~any(D(i,:))
        D(i,i) = true;
        for j=i+1:n
            IsDuplicate = true;
            for k=1:m
                IsDuplicate = IsDuplicate && abs(Xg(i,k)-Xg(j,k)) < tol*R(k);
            end
            D(i,j) = IsDuplicate;
            D(j,i) = IsDuplicate;
        end
    else
        % already found this operating point
        first = find(D(i,:),1,'first');
        D(i,:) = D(first,:);
    end
end

% keep first
Dfirst = D;
Dlast = D;
for i=1:n
    % remove first element so first element is kept
    first = find(D(i,:),1,'first');
    Dfirst(i,first) = false;
    % remove last element so last element is kept
    last = find(D(i,:),1,'last');
    Dlast(i,last) = false;
end
KeepFirst = ~any(Dfirst,1);
KeepLast = ~any(Dlast,1);