i got error at the line"strea​m(j).Posit​ion=stream​(j).Positi​on+2.*rand​(1).*(sea.​Position-s​tream(j).P​osition);" in Subscript indices must either be real positive integers or logicals. please help me.

2 views (last 30 days)
for i=1:Npop
pop(i).Position=LB+(UB-LB).*rand;
pop(i).Cost=objective_function(pop(i).Position);
end
[pop, F]=NonDominatedSorting(pop); % Non-dominated sorting
pop=CalcCrowdingDistance(pop,F); % Calculate crowding distance
pop=SortPopulation(pop); % Sort population
%------------- Forming Sea, Rivers, and Streams --------------------------
sea=pop(1);
river=pop(2:Nsr);
stream=pop(Nsr+1:end);
cs=[sea.CrowdingDistance';[river.CrowdingDistance]';stream(1).CrowdingDistance];
f=0;
if length(unique(cs))~=1
CN=cs-max(cs);
else
CN=cs;
f=1;
end
NS=round(abs(CN/(sum(CN)+eps))*N_stream);
if f~=1
NS(end)=[];
end
NS=sort(NS,'descend');
% ------------------------- Modification on NS -----------------------
i=Nsr;
while sum(NS)>N_stream
if NS(i)>1
NS(i)=NS(i)-1;
else
i=i-1;
end
end
i=1;
while sum(NS)<N_stream
NS(i)=NS(i)+1;
end
if find(NS==0)
index=find(NS==0);
for i=1:size(index,1)
while NS(index(i))==0
NS(index(i))=NS(index(i))+round(NS(i)/6);
NS(i)=NS(i)-round(NS(i)/6);
end
end
end
NS=sort(NS,'descend');
NB=NS(2:end);
FF=zeros(max_it,numel(sea.Cost));
for i=1:max_it
%---------- Moving stream to sea---------------------------------------
for j=1:NS(1)
stream(j).Position=stream(j).Position+2.*rand(1).*(sea.Position-stream(j).Position);
stream(j).Position=min(stream(j).Position,UB);
stream(j).Position=max(stream(j).Position,LB);
  1 Comment
KSSV
KSSV on 24 Mar 2017
How we can test the code without knowing any inputs? Any ways check the value of j it is either 0 or negative that's why error poped out.

Sign in to comment.

Answers (0)

Categories

Find more on Mathematics and Optimization 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!