MATLAB: S-functions with ode45 in Matlab

ode45 simulations-functionsimulink

Hi, all! I have a dynamical system written in an S-function and I want to simulate it in a Matlab loop. I use ode45 on the S-function and it seems to work (it runs with no errors). However it's not the result I was expecting. After that, I took the code from the S-function and plugged into a regular dx = f(t,x,u) function and when I applied ode45 to f, I got what I was looking for.
So, my question: what's wrong with applying ode45 to an S-function?

Best Answer

Ok, I solved it by creating a new function handle to the S-function.
Smth like:
f = @(t,x,u,params)SfunctionName(t,x,u,1,params{:});
[Tk,Xk] = ode45(f, [T(k) T(k+1)], x, options, U(k), params);
Best