Set an
error breakpoint
then run your code. When it stops, MATLAB will be paused in the location where the error occurred. To make it clearer to understand which instruction caused the error, you may want to rewrite this line so each instruction is on its own line.
fork=1:Noants
tour=ant(k).Tour;
forl=1:noNodes
tau(tour(l),l)=tau(tour(l),l)+Q/ant(k).Cost;
end
end
Look at the
size
of each of the arrays being indexed into on the line in question. Depending on the specific line, some of the questions you may need to ask are:
- Does ant have at least k elements?
- Does tour have at least l elements?
- Does tau have at least tour(l) rows and at least l columns?
The answer to at least one of those questions is going to be no. Once you know which one(s) work your way backwards through your code, adding breakpoints and/or conditional breakpoints on earlier lines and rerunning your code until you've identified where your code isn't doing what you expect and/or want it to do.