MATLAB: How to initialize internal variable of s-function every simulation

initialize internal state of s-functions-functionsfcnsfunctionsimulationsimulink

Hello 😀
I'm having a problem with s-function.
I'd like to initialize all value of s-function, but I can't.
I think the last value of internal variable is not initialized when I execute simulation again.
So, before execute simulation, I'd like to initialize internal state of s-function.
I'm wating for your answers.
Thank you.

Best Answer

Add code to the mdlStart() or mdlInitialize() functions in the SFunctionto reset state variables.