www.gusucode.com > matlab双曲多项式工具箱(HPT) > matlab双曲多项式工具箱(HPT)/matlab双曲多项式工具箱(HPT)/hyperbolic_polynomial_toolbox/testing_functions/robust_unique.m

    function ru = robust_unique(vec,tol)
% function ru = robust_unique(vec,tol)
%
% Collect the elements from a vector which
% are "essentially" unique to a given epsilon tolerance.
%
% Input:
%   vec - A vector of reals.
%   tol (optional) - Acceptable tolerance for two numbers to be considered equal.
%	Default is 1e-12.
% Output:
%   ru - A vector containing elements from vec such that any two elements
%	in ru are separated by at least tol and any element in setdiff(vec,ru)
%	is within tol of an element in ru.

if nargin < 2
	tol = 1e-12;
end
ru = [];
for i =1:length(vec)
	if(~any(abs(vec(i)-ru)<tol))
		ru = [ru vec(i)];
	end
end