index exceeds the number of array elements (1).
Show older comments
fobj=min(e);
Max_iter=20;
N=30;
dim=2;
lb=[2;1000];
ub=[15;10000];
if size(ub,1)==1
ub=ones(dim,1)*ub;
lb=ones(dim,1)*lb;
end
%Initialize the population of grasshoppers
if size(ub,1)==1
X=rand(N,dim).*(ub-lb)+lb;
end
if size(ub,1)>1
for i=1:dim
high=ub(i);
low=lb(i);
X(:,i)=rand(1,N).*(high-low)+low;
end
end
X1=round(X);
GrassHopperPositions=X1;
GrassHopperFitness = zeros(1,N);
fitness_history=zeros(N,Max_iter);
position_history=zeros(N,Max_iter,dim);
Convergence_curve=zeros(1,Max_iter);
Trajectories=zeros(N,Max_iter);
cMax=1;
cMin=0.00004;
%Calculate the fitness of initial grasshoppers
for i=1:size(GrassHopperPositions,1)
GrassHopperFitness(1,i)=fobj(GrassHopperPositions(i,:));
fitness_history(i,1)=GrassHopperFitness(1,i);
position_history(i,1,:)=GrassHopperPositions(i,:);
Trajectories(:,1)=GrassHopperPositions(:,1);
end
1 Comment
Pavan Malghan
on 2 Mar 2021
Accepted Answer
More Answers (0)
Categories
Find more on Matrix Indexing 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!