Error: NSGA-II algorithm for the cost and satisfaction objectives
7 views (last 30 days)
Show older comments
When running the main program main.m in MATLAB 2016a, the following error message keeps appearing. Please modify the code based on the error message below to ensure that the modified code runs smoothly and outputs the correct results.
"Index exceeds matrix dimensions."
Error in CalcCrowdingDistance (line 27):
d(so(i), j) = abs(cj(i+1) - cj(i-1)) / abs(cj(1) - cj(end));
Error in nsga2 (line 95):
pop = CalcCrowdingDistance(pop, F);
0 Comments
Answers (1)
Arnav
on 8 Nov 2024 at 6:28
The error is due to accessing the matrix cj with an index i exceeding its dimensions in line 27 of CalcCrowdingDistance.m. The index i goes from 2 to n-1.
Replacing line 12
n = numel(F{k});
with
n = numel(Costs);
fixes the error as the length of cj is the length of Costs and not F{k}.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!