How to debug only the N-th call to a function?

2 Ansichten (letzte 30 Tage)
Oliver Johnson
Oliver Johnson am 10 Sep. 2015
Kommentiert: Joseph Cheng am 10 Sep. 2015
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!

Akzeptierte Antwort

the cyclist
the cyclist am 10 Sep. 2015
Bearbeitet: the cyclist am 10 Sep. 2015
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 Kommentar
Joseph Cheng
Joseph Cheng am 10 Sep. 2015
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Get Started with Optimization Toolbox finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by