MATLAB: Implemention of a state machine in ode45 (not in Simulink)

MATLABode45state machinestateflow

How can I implement a state machine (just like Simulink StateFlow) in Matlab ode45, without using Simulink?

Best Answer

You cannot. State machines imply discontinuous equations. Any one call to ode45 must have continuous equations.
You need to use event functions to detect the change of state and signal termination of integration. Then use the output of ode45 to provide the initial values to another ode45 call.
Related Question