sort.m

来自「一些用matlab编写的经典遗传算法算例。可以用于解决许多优化问题」· M 代码 · 共 13 行

M
13
字号
function varargout = sort(chr)
% SORT - Sort in ascending order.  For a vector of chromosomes, sort(x)
%    sorts the objects of x in ascending order, with the respect to
%    the fitness of the chromosomes. 
%    [y i] = sort(x) also returns an index vector.
for k=1:length(chr)
  tmp(k)=chr(k).fitness;
end
[q ind]=sort(tmp);
varargout{1}=chr(ind);
varargout{2}=ind;

⌨️ 快捷键说明

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