www.gusucode.com > mbctools 工具箱 matlab 源码程序 > mbctools/@xregdataset/private/getUniqueTestnum.m

    function uniqueNum = getUniqueTestnum(num)
% GETUNIQUETESTNUM

%  Copyright 2000-2004 The MathWorks, Inc. and Ford Global Technologies, Inc.




% Get rid of any infinities and NaNs
num(~isfinite(num)) = 0;

% By default we assume the numbers are unique
uniqueNum = num;
if numel(num) == 1
	return
end

[sNum, i] = sort(num);

d = diff(sNum);
% Increment the find by 1 because diff reduces the length by 1
j = find(d == 0) + 1;
% If no numbers are the same then return with uniqueNum = num
if isempty(j)
	return
end
% Need to deal with non-unique numbers so get the last integer in the sort
lastInt = floor(sNum(end));
% Get new index numbers
newIndex = (1:length(j)) + lastInt;
% Reassign index numbers in ascending order
i = sort(i(j));
uniqueNum(i) = newIndex;