MATLAB: S-Function Builder Simple Integrator Implementation

s-functions-function buildersfunctionssimulink

Hello,
I'm pretty new in the Matlab S-Function world and I'm struggling with implementing a simple integrator S-Function using the S-Function Builder Block in Simulink.
I'm using the S-Function builder block as it easily allows me to control my input and output port dimension size under the Port Parameter Properties.
The single continuous time integrator I'm trying to model is the following:
xdot = u
y = x
Unfortunately the term I'm writing inside the "Continuous Derivative" tab doesn't represent the derivative state and the final compiled S-Function doesn't act as an integrator. The term I'm writing in the Output and Continuous Derivative Tabs are the following:
y0[0] = u0[0]; (u0 is the port 1 input state and y0 is the output port variable)
dx[0] = u0[0]; (Derivative Tab code)
I'd appreciate it if you could let me know what I'm doing wrong that this S-Function only acts as a direct feedthrough.
Thanks in advance. Nima

Best Answer

Your Derivatives tab looks right, but I think you need this in your Outputs tab:
y0[0] = xC[0];
Note that this is what "y=x" corresponds to.