Hi all,(adsbygoogle = window.adsbygoogle || []).push({});

I'm having some issues with Matlab.

I'm running ode45 inside a function which is called repeatedly in a finite loop. As it is being called, Matlab is plotting and saving the data externally.

Here's a quick pseudo-code

This is all well and good, but as soon as ode45 is unable to solve a DE (were the solution does not converge), Matlab gets stuck in an (almost?) infinite loop repeatedly calling ode45 until a solution is found. I can obviously stop this using "Ctrl-C" but this will screw up the data I'm trying to gather and plot.Code (Text):

func1 ( )

loop {

data = func2 (variables)

save data

plot data

}

end func1

func2 ( input vars)

--

--

options = odeset('events',@missile_event, 'RelTol',1e-14);

[t, x, te, xe, ie] = ode45 ( @de, [t0 tf], x0, options );

--

--

plot x vs t etc..

--

--

return data;

end

Is there a way to get ode45 to return some value if it takes more than x seconds to find a solution? Or perhaps get it to stop executing func2 and resume func1 (see above code).

I am already using the events function to stop ode45 as soon as it has converged close to the solution.

i.e,

Thanks in advance.Code (Text):

function [lookfor stop direction ] = missile_event(t, x)

r = sqrt(x(1)^2 + x(2)^2) ;

lookfor = r - 0.1;

stop = 1;

direction = 0;

**Physics Forums - The Fusion of Science and Community**

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Stoping a specific matlab function

Loading...

Similar Threads - Stoping specific matlab | Date |
---|---|

How to program this in Matlab | Feb 28, 2018 |

How to get specific frequency and time values for .wav file | Mar 3, 2015 |

Solving equations involving specific elements of matrices in MATLAB? | Mar 23, 2014 |

Matlab question: How to pick specific value from column vector | Jan 16, 2014 |

Rotate the wheel to a specific point | Nov 20, 2012 |

**Physics Forums - The Fusion of Science and Community**