seq_arrange.m

来自「模式识别分类方法中的最近邻准则方法。内有详细说明文档。」· M 代码 · 共 37 行

M
37
字号
% 给出x中元素按大小排序的排位值,允许出现并列的情况!!!

function y=seq_arrange(x)
y=zeros(1,length(x));

repeat=0;
time=1;% 计算排过序的次数,最后把所有元素都排一次
place=1;
while time<=length(x)
   [v p]=min(x);
   y(p)=place;
   x(p)=Inf;
   time=time+1;
   % to check whether there are any elements have the same value
   % if there are not, flag=0,if there are, flag save their number.
   flag=0;
   for j=1:length(x)
      if (v==x(j))&(j~=p)
         flag=flag+1;
      end
   end

   if flag~=0
      for k=1:length(x)
         if (x(k)==v)&(k~=p)
            y(k)=place;
            x(k)=Inf;
            repeat=repeat+1;
            time=time+1;
         end
      end
      place=place+flag;
   end
   place=place+1;
end
%%编这么个子函数花了俩多点,晕,倒,败,昏.....累死我啦,......
%%%Author: Feng Shuo%%%%%%%%

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?