Info

This question is closed. Reopen it to edit or answer.

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

1 view (last 30 days)
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 Comments
Walter Roberson
Walter Roberson on 5 Jan 2018
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 on 5 Jan 2018
yes you are right. you will find attached the function "initial_fitness_function"

Answers (1)

Walter Roberson
Walter Roberson on 5 Jan 2018
Edited: Walter Roberson on 5 Jan 2018
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 Comments
imen boujnah
imen boujnah on 6 Jan 2018
Edited: imen boujnah on 6 Jan 2018
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 on 6 Jan 2018
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 ?

This question is closed.

Tags

Community Treasure Hunt

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

Start Hunting!