I am trying to run ode45 once using an event function, but have it stop after the 50th event has occurred. I am currently using a persistent counter to keep track of events, but am missing the logic to update the counter. Below is the code for my event function. I do not want to call ode45 50 times by updating the initial conditions with the terminal conditions from the previous call.
function [value,isterminal,direction] = y0eventPoincare(t,y)persistent icountif (isempty(icount)) icount=0;endif icount<50value=y(2);isterminal=0;direction=1;if (**Missing Logic**) %Event has occured
icount=icount+1;endendif icount==50value=y(2); if true % code
end isterminal=1; direction=1; endend
Best Answer