Breakpoint-counter: Only stop at Matlab breakpoint the second (nth) time it is hit -


i looking way set conditional breakpoint stops second (or n-th) time condition met, example:

function f = myfunc(x) t = 1:1000    x = x+x^0.5; %i want stop here second time function called , t == 666 end f = x; 

i know how stop @ breakpoint each time condition met, if want @ second time hit first need wait few minutes, hit f5 , wait few minutes. quite annoying makes me lose focus once more required. if want @ 10th time, worse.

i looking solution not require me adjust code of function in need stop.

here's fun idea, think gives partial solution.

write function mystop.m:

function flag = mystop  persistent counter  if isempty(counter)     counter = 0; else     counter = counter+1; end  if counter>=2     flag = true; else     flag = false; end 

now set conditional breakpoint within myfunc @ line x = x+x^0.5;, condition being

t == 666 && feval(@()mystop) 

set test function exercise myfunc few times:

function [f1,f2,f3,f4,f5] = mytest  clear mystop  f1= myfunc(1) f2= myfunc(2) f3= myfunc(3) f4= myfunc(4) f5= myfunc(5) 

when run mytest, should stop second time line in myfunc hit (and t 666) - in other words, while f2 being calculated.

note need include line clear mystop, in order reset persistent variable between calls mytest. alternatively, manually call clear mystop between runs of mytest.

obviously - if want stop after 3rd, 10th, nth time etc, modify condition counter>=2 above counter>=n.


Comments

Popular posts from this blog

php - mySql Join with 4 tables -

css - Text drops down with smaller window -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -