Info
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
how can i fix this problem : Index exceeds matrix dimensions ?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Walter Roberson
el 5 de En. de 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.
Respuestas (1)
Walter Roberson
el 5 de En. de 2018
Editada: Walter Roberson
el 5 de En. de 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 comentarios
Walter Roberson
el 6 de En. de 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 ?
La pregunta está cerrada.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!