States Not Visible in Coder-Generated S-Function Blocks

3 views (last 30 days)
I'm trying to use the Simulink coder to codegen a fairly complex model into an S-Function block in order to improve the performance of the model. I can do this, but when I do, all of the states in the model vanish and become inaccessible from outside the S-Funcion. When I call Simulink.BlockDiagram.getInitialState() on the model with the generated S-Function block, it returns an empty array.
I have previously been able to access states inside generated S-Function blocks which were created for less complex models, so I know it should be possible. The states are (for the moment) just a bunch of Unit Delay blocks located inside a (non-Atomic) Subsystem. There are Reference Models in the model, but there are currently not any states in the Reference Models.
I've dug around in some of the codegen'd C-code, and the "Subsystem_sf.c" file actually calls "ssSetNumDiscStates(S, 0);", explicitly setting the number of discrete states to zero. This is dispite the same function actually initializing all of the variables for the states, which are currently set to "ImportedExternPointer". (I have tried other settings of the Code Generation Storage Class, and it does not appear to make any difference).
Any idea why my states are disappearing on me?
Kaustubha Govind
Kaustubha Govind on 4 Jun 2013
Greg: The fact that the behavior changes with the presence of referenced models seems suspicious to me. Perhaps you should report this to MathWorks Support?

Sign in to comment.

Answers (0)


Find more on Simulink Coder in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!