How to debug only the N-th call to a function?
조회 수: 1 (최근 30일)
이전 댓글 표시
I have a script that calls fmincon to minimize a function, call it @myfun. The solver makes it through 3 iterations (each with dozens of function evaluations of @myfun), and then it seems to be forever stuck on the 4th iteration. Every time I use ctrl+c to exit the function terminates during a particular subfunction of @myfun, so I suspect something is going on there (i.e. the subfunction is taking forever to evaluate with a particular input that the solver is giving it). In order to investigate this I could put a breakpoint in the subfunction, but then I would have to press F5 about 1000 times before getting to the point where the problem is. What is the best way to debug something like this (where the breakpoint needs to be inside of a function that is called many times, but you don't want to stop until the N-th evaluation)?
Thanks!
댓글 수: 0
채택된 답변
the cyclist
2015년 9월 10일
편집: the cyclist
2015년 9월 10일
One possible solution is to set a condition breakpoint. You can read more here: http://www.mathworks.com/help/matlab/matlab_prog/set-breakpoints.html.
You might need to add some kind of global counter, given your situation.
댓글 수: 1
Joseph Cheng
2015년 9월 10일
I learned something completely new today! thanks cyclist. Before knowing this I personally stuck snippits of debug code like:
%%%%%debug
if interestingVariable==somenumber
disp('debug');
end
%%%%debug end
%line you're interested here
or since it is a subfunction display the output of a critical computation instead of debug.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Get Started with Optimization Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!