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

采纳的回答

Andreas Goser
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 CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by