Do you know (before calling the ODE solver the first time) when the ODE function that you're trying to solve changes based on the condition? If so call ode45 to solve the first ODE function up until that point then use the final result from solving that first ODE function as the initial condition for a second ode45 call using the second ODE function.
As a slightly more concrete explanation, let's say you know that the ODE you need to solve changes every 2 seconds. Solve the first ODE with a time span of [0 2]. Use the solution of that first ODE to define the initial condition for the second ODE and solve that second ODE with a time span of [2 4]. Repeat that process, using the solution of the second ODE to generate the initial condition for the third ODE and so on.
If you don't know exactly when the ODE you're trying to solve will change based on the condition, use an Events function. There's an example that uses Events in MATLAB called ballode. It's not exactly the same as the situation you described, since the ODE doesn't change, but if you imagine passing different function handles into the ODE solver based on which condition/event is "active" you should be able to adapt it to suit your purposes.
Best Answer