Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

how can i fix this problem : Index exceeds matrix dimensions ?

조회 수: 1 (최근 30일)
imen boujnah
imen boujnah 2018년 1월 4일
마감: MATLAB Answer Bot 2021년 8월 20일
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
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.
imen boujnah
imen boujnah 2018년 1월 5일
yes you are right. you will find attached the function "initial_fitness_function"

답변 (1개)

Walter Roberson
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
imen boujnah
imen boujnah 2018년 1월 6일
편집: imen boujnah 2018년 1월 6일
i put this instruction ss(i,:) = y(b(1:M)); but the same problem still persists : Index exceeds matrix dimensions.
Error in initial_fitness_value (line 21) ss(i,:) = y(b(1:M));
Error in essai_version_standard (line 71) FV_x0 = fun(M,NP,x0,DM1,DM2,pm1,pm2) ;
Walter Roberson
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!

Translated by