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

1 visualizzazione (ultimi 30 giorni)
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!

Risposta accettata

the cyclist
the cyclist il 10 Set 2015
Modificato: the cyclist il 10 Set 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 Commento
Joseph Cheng
Joseph Cheng il 10 Set 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.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Get Started with Optimization Toolbox in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by