index exceeds matrix dimensions

% Update the position and velocity of each particle (except the elites)
max_iter=300;
b=0.6;
mu=2.34;
x(1)=0.6;
for k=1:max_iter
if x(k)<0.7
x(k+1)=b*mu*x(k)+x(k)*(1-b);
end
if x(k)>=0.7
x(k+1)=b*mu*(1-x(k))+x(k)*(1-b);
end
rvalue=(x(k+1));
end
for i = OPTIONS.Keep+1 : OPTIONS.popsize
r = rvalue(3,OPTIONS.numVar); %Error of matrix exceeds dimensions
x = Population(i).chrom;
deltaVpersonal = OPTIONS.c1 * r (1,:).* (pbest(i).chrom - x);
deltaVswarm = OPTIONS.c2 * r(2,:) .* (gbest.chrom - x);
deltaVneighborhood = OPTIONS.c3 * r(3,:) .* (nbest(i).chrom - x);
vel(i,:) = OPTIONS.w * vel(i,:) + deltaVpersonal + deltaVswarm + deltaVneighborhood;
Population(i).chrom = x + vel(i,:);
end

1 件のコメント

deepak kumar
deepak kumar 2019 年 10 月 5 日
Sir, after executing as you say, the ans is 1 1 and 75.......

サインインしてコメントする。

回答 (1 件)

Image Analyst
Image Analyst 2019 年 10 月 5 日

0 投票

Either rvalue does not have 3 or more rows, or rvalue does not have OPTIONS.numVar columns. What does this show in the command window if you put it before that line?
size(rvalue)
OPTIONS.numVar

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

質問済み:

2019 年 10 月 5 日

コメント済み:

2019 年 10 月 5 日

Community Treasure Hunt

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

Start Hunting!

Translated by