Skip to Main Content Skip to Search
Product Documentation

Structure Parameters and Generated Code

About Structure Parameters and Generated Code

Structure parameters provide a way to improve generated code to use structures rather multiple separate variables. You also have the option of configuring the appearance of a structure parameter in generated code.

For more information about structure parameters, seeUsing Structure Parameters in the Simulink documentation. For an example of how to convert a model that uses unstructured workspace variables to a model that uses structure parameters, see sldemo_applyVarStruct.

Configure a Structure Parameter to Appear in Generated Code

By default, structure parameters do not appear in generated code. Structure parameters include numeric variables and the code generator inlines numeric values.

To make structure type definition appear in generated code for a structure parameter,

  1. Create a Simulink.Parameter object.

  2. Define the object value to be the parameter structure.

  3. Define the object storage class to be a value other than Auto.

The code generator places a structure type definition or the tunable parameter structure in model_types.h. By default, the code generator identifies the type with a nondescriptive, automatically generated name, such as struct_z98c0D2qc4btL.

For information on how to control the naming of the type, see Control the Name of a Structure Parameter Type. For an example, see sldemo_applyVarStruct

Control the Name of a Structure Parameter Type

To control the naming of a structure parameter type, by using a Simulink.Bus object to specify the data type of the Simulink.Parameter object.

  1. Use Simulink.Bus.createObject to create a bus object with the same shape as the parameter structure. For example:

    busInfo=Simulink.Bus.createObject(ControlParam.Value);
  2. Assign the bus object name to the data type property of the parameter object.

    ParamType=eval(busInfo.busName);
    ControlParam.DataType='Bus: ParamType';

Only Simulink.Parameter can accept the bus object name as a data type.

For an example, see sldemo_applyVarStruct

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS