Code generation for structs defined in the base workspace

14 visualizzazioni (ultimi 30 giorni)
Hi, I'm trying to generate C code from a Simulink model so that the variables I have defined in the base workspace become tunable. I have a Simulink.Parameter defined in my base workspace with a struct assigned to its "Value" parameter. This is helping me in creating a fixed variable for each instance of that parameter being used when I generate code from it. However, the struct that gets defined in the generated code is named automatically by the coder in the header file and contains a suffix such as "struct_W2E3uGucd7iucczLeIRchB" (see attached image #1). This struct is then referenced by the Simulink.Parameter that it is attached to in the C file (see attached image #2).
Is there a setting in the model configuration which I can use to define what the struct would be named as in the generated code? Just for reference, I'm using an ERT system target file as part of the model configuration.

Risposte (1)

Matthew Englehart
Matthew Englehart il 8 Lug 2025
Hi Mihir,
you need to define a Simulink Bus object whose structure matches that of the struct value, and then assign the DataType of the Simulink.Parameter object to be that bus type. You can create this bus object using the convenient Simulink.Bus.createObject() function.
When you do this, the data type that is used in the generated code will be a struct type whose name is the name of the Bus object, instead of the "anonymous" struct type you are seeing now.
Moreover, for best results, it is often advisable to set the DataScope of the Bus object to "Exported" rather than its default, "Auto".

Community Treasure Hunt

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

Start Hunting!

Translated by