MATLAB: How to stop an ode-solver if integration takes too long

interrupt ode solver

Hi all,
I am working with implicit ode15i solver.
I receive results within seconds for more than 80 parameters to solve. However, sometimes it seems it gets stuck – no progress after hours. I can reproduce that, so I am sure I have chosen bad initial conditions. Is there a way to interrupt the integration after certain time to start new with different initial conditions? Something like a timing option?
I know about the event-function but this is for events given by the system only as far as I understood.
Thanks a lot in advance. Best, Franziska

Best Answer

At the start of your code:
StartTime=clock;
At the end of each loop/the point you might want to exit
TimeElapsed=clock-StartTime;
if TimeElapsed(end)>10 %Set it to a value that you want (I chose 10 seconds)
return
end
Look at the clock function to understand this more.