MATLAB: Simulink – Change continuous state value at a given time point

continuous statelevel-2 matlab s-functionsimulink

Hello, I have a model with a Level-2 MATLAB S-Function simulating continuous states. At a given time point I want one of the continuous state values to increase by a given value. It is even not really important, that the value changes on exactly that time point.
I tried to solve it with a signal, that changes from 0 to the value at the time point and then used the Difference, or the Memory block to get the signal to only be the value at one timestep, otherwise 0. Then added the value to the continuous state in the s-function output. But with this method the value is somehow integrated and the increase of the continuous state much too high.
I am glad for any help.

Best Answer

If you want to generate a "jump" in your continuous state, you must reset the block. This can be done in many ways. For example placing your block in an Enabled subsystem and turning it off for one sample and then on again. That way you should be able to reset your state to a desired value, for example coming from an input port or any other computation.