Tell the what is "I" represents and explain by seeing my code?

1 回表示 (過去 30 日間)
Matlab111
Matlab111 2014 年 9 月 10 日
コメント済み: Matlab111 2014 年 9 月 10 日
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 Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by