Tell the what is "I" represents and explain by seeing my code?
1 次查看(过去 30 天)
显示 更早的评论
I need to know the what "I" represents in this program and how they are getting that value explain me clearly please... in program ("[fmin,I]=min(Fitness);") this part
function [best,fmin]=bat_algorithm(para)
if nargin<1, para=[5 2 0.5 0.5]; end
n=para(1);
d=10;
Lb=-2*ones(1,d);
Ub=2*ones(1,d);
for i=1:n,
Sol(i,:)=Lb+(Ub-Lb).*rand(1,d);
Sol
Fitness(i)=Fun(Sol(i,:));
Fitness
end
[fmin,I]=min(Fitness);
[fmin,I]
I
best=Sol(I,:);
I
best
function z=Fun(u)
% Sphere function with fmin=0 at (0,0,...,0)
z=sum(u.^2);
z
0 个评论
采纳的回答
Andreas Goser
2014-9-10
Quoting the documentation for the command MIN:
[C,I] = min(...) finds the indices of the minimum values of A, and returns them in output vector I. If there are several identical minimum values, the index of the first one found is returned.
So you get an index. Example code
A=[2 4 3 5 2]
[x,y]=min(A)
2 is the smallest content. y is index 1 then.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!