MATLAB: In the code below, what does ind do

ind genetic algorithm

cost=feval(ff,pop); %evaluate function
[cost,ind]=sort(cost,'descend'); %sorts in descending order
pop=pop(ind,:);

Best Answer

It evaluates a function called ‘ff’ with the argument ‘pop’, and assigns it to the variable ‘cost’. It then sorts ‘cost’, gets the associated indices (‘ind’)into the original vector, and uses those indices to re-define ‘pop’, sorting it according to ’cost’.