sort.m
来自「Passino所提出的细菌优化算法matlab源程序」· M 代码 · 共 20 行
M
20 行
function [frogs] = sort(frogs)
% Sort in ascending order the angles of frogp object ant its associate fields (ID, angle, gap, supergap)
global N
for i = 1: N
% Gets the angles from frogs
tmp_angle(i) = get(frogs(i),'angle');
end
%Sorts them and stores their indices
[tmp_angle,ind]=sort(tmp_angle);
temp = frogs;
%Now stores the angles in ascendent order with all their fields
for i = 1:N
%Two methods are called here: set is called first and then subsasgn is called
frogs(i) = set(temp(i), 'ID', get(temp(ind(i)),'ID'), 'angle', get(temp(ind(i)),'angle'),...
'gap', get(temp(ind(i)),'gap'), 'supergap', get(temp(ind(i)),'supergap'));
end
return
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?