Info
この質問は閉じられています。 編集または回答するには再度開いてください。
how can i fix this problem : Index exceeds matrix dimensions ?
1 回表示 (過去 30 日間)
古いコメントを表示
when i run my code the following statements display always : Index exceeds matrix dimensions.
Error in Fitness_value (line 17) sss(i,:)=y(b);
Error in essai_version_standard (line 100) FV_x = fun2 (M,NP,x,DM1,DM2,pm1,pm2);
4 件のコメント
Walter Roberson
2018 年 1 月 5 日
Your code calls initial_fitness_function but we at home do not have a function by that name. It is not part of MATLAB. The name of the function would suggest that you forgot to post all of code needed for us to test your code.
回答 (1 件)
Walter Roberson
2018 年 1 月 5 日
編集済み: Walter Roberson
2018 年 1 月 5 日
in Fitness_function you have
N = 5; % nbre des jobs sur M1 %
M= randi ([4 6],1,1); % nbre des jobs sur M2 (N>= M)
suppose M is generated as 4.
You then have
for i =1 : NP
A ( i , 1 : M )= randperm (M);
end
so those rows would then have 4 columns.
You have
for i = 1 :NP
[ a , b ]= sort (x(i,:)); %SPV rule
y=A(i,:);
sss(i,:)=y(b);
end
After the sort(), b will contain every integer from 1 to size(x,2) . x is 5 columns wide, so some location in b will be 5. On the line after that, one particular row of A is extracted, and that row will be 4 wide because M was randomly generated as 4. You then try to index that row of 4 with an index that is certain to include the value 5, which is going to fail.
Possibly you want
sss(i,:) = y(b(1:M));
2 件のコメント
Walter Roberson
2018 年 1 月 6 日
You are right, that will not help.
I think you need to redesign that section of code. Why are you trying to use 4 indices (width of x) to fill 5 slots (N=5) ? Why are you not restricting N to be at most size(x,2) ?
I also do not understand your code
N = 5; % nbre des jobs sur M1 %
M= randi ([4 6],1,1); % nbre des jobs sur M2 (N>= M)
if M > N
M=N ;
end
if you know that N is 5, why are you randomly generating M in the range 4 to 6 when your comment says N>=M ?
この質問は閉じられています。
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!