plz explain error IN PSO CODE
Show older comments
Undefined operator '<' for input arguments of type 'struct'.
Error in TrainAnfisUsingPSO>RunPSO (line 103)
if particle(i).Best.Cost<BestSol.Cost
CODE IS HERE:
empty_particle.Position=[];
empty_particle.Cost=[];
empty_particle.Velocity=[];
empty_particle.Best.Position=[];
empty_particle.Best.Cost=[];
particle=repmat(empty_particle,nPop,1);
BestSol.Cost=inf;
for i=1:nPop
% Initialize Position
if i>1
particle(i).Position=unifrnd(VarMin,VarMax,VarSize);
else
particle(i).Position=ones(VarSize);
end
% Initialize Velocity
particle(i).Velocity=zeros(VarSize);
% Evaluation
particle(i).Cost=CostFunction(particle(i).Position);
% Update Personal Best
particle(i).Best.Position=particle(i).Position;
particle(i).Best.Cost=particle(i).Cost;
% Update Global Best
var1=particle(i).Best.Cost;
var2=BestSol.Cost;
if particle(i).Best.Cost<BestSol.Cost %this line
BestSol=particle(i).Best;
end
end
3 Comments
Walter Roberson
on 16 Feb 2018
CostFunction is returning a struct rather than a numeric value. We would need to see the code to figure out why.
jasleen kaur
on 17 Feb 2018
Edited: Walter Roberson
on 17 Feb 2018
jasleen kaur
on 17 Feb 2018
Answers (0)
Categories
Find more on Particle Swarm in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!