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

1 vue (au cours des 30 derniers jours)
Matlab111
Matlab111 le 10 Sep 2014
Commenté : Matlab111 le 10 Sep 2014
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

Réponse acceptée

Andreas Goser
Andreas Goser le 10 Sep 2014
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.

Plus de réponses (0)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by