I think you are using the wrong tool for this. ode45( ) is an adaptive integrator, which means that it has the freedom to change stepsizes and make derivative function calls at times that are not necessarily increasing. E.g. ode45( ) might try to make a step with dt, then detect that the estimated error terms are too large, so it will decrease dt and try again. This will result in ode45( ) making calls to your derivative function at times that are not strictly increasing ... there will be some calls at times that are before the time of an earlier call. I think this is going to mess up your feedback control that you have inside your derivative function. Calculating your feedback control at the end of your derivative function and making it persistent inside the derivative function so that it gets used in the next integration step isn't going to fix this problem.
I would offer two things you could try:
1) Use your own hand-coded RK4 code where you can dictate that the derivative function calls are always going forward in time, AND at the same time you can dictate when to calculate and apply your control feedback, which will be fed into the next integration step. The RK4 code isn't that difficult to write and this is probably the simplest thing to try.
2) Code things up in Simulink with an actual feedback loop (you will need to put in a feedback delay to avoid an algebraic loop error).