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

1 visualización (últimos 30 días)
Matlab111
Matlab111 el 10 de Sept. de 2014
Comentada: Matlab111 el 10 de Sept. de 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

Respuesta aceptada

Andreas Goser
Andreas Goser el 10 de Sept. de 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.

Más respuestas (0)

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by