Index exceed matrix dimensions

6 ビュー (過去 30 日間)
Esraa Abdelhalim
Esraa Abdelhalim 2017 年 11 月 28 日
コメント済み: Walter Roberson 2017 年 11 月 30 日
I am writing this function and for loc = 5 it works fine for any number of popsizes but when I extend it to larger sizes it gives error "Index exceeds matrix dimension" kindly find the code below I tried to test it for popsize = 10 and I found that the f1 and f2 exceeds the 10 counts i dont know why and ofcourse f(i) only contains 10 values hence i get this error I hope I can find help;
function [ f ] = VRPObj8Old1 ( x, popsize, loc, d, a)
f = zeros(popsize,1);
for i = 1: popsize
f1 = 0;
for l = 1:loc
f1 = f1 + x( 1, l, i) * a;
end
f2 = 0;
for j = 1:loc
for o = 1:loc
f2 = f2 + x( j, o, i) * d(j , o);
end
end
f(i) = f1 + f2;
end

回答 (1 件)

Roger Stafford
Roger Stafford 2017 年 11 月 28 日
You will get that error message if either 'd' is not at least of size loc-by-loc, or 'x' is not at least of size loc-by-loc-by-popsize.
  2 件のコメント
Esraa Abdelhalim
Esraa Abdelhalim 2017 年 11 月 29 日
Actually I tested this on a 5by5 (loc=5) matrix and it worked fine but when I increase it to larger size it gives me that error ..
Walter Roberson
Walter Roberson 2017 年 11 月 30 日
At the time of failure, what is size(x), size(d), size(a), and what are popsize and loc ?

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

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by