MATLAB: How to use nested structures in the generated code

Embedded Coder

How can I use nested structures in my generated code?
I would like to use a few nested structures to capture most of the data used by my model, but Embedded Coder is splitting it into multiple separate variables.

Best Answer

The attached files provide two examples of using nested structures in Embedded Coder generated code. Open the "struct_csc_param_init.m" script to see how the nested structures are set up and run it to observe the resulting generated code.
The first example produces a nested structure in the generated code from separate variables in the Base Workspace using the Struct Custom Storage Class.
Here is a link to the MATLAB Documentation describing the "Struct custom storage class"
The second example produces a nested structure in the generated code based on a nested structure in the Base Workspace.
Both example use the "Simulink.Parameter" object as a way to control the format of the generated code.
Here is a linke to the MATLAB Documentation describing the "Simulink.Parameter" object.