Main Content

Share Parameters with Simulink and the MATLAB Workspace

A parameter is a constant data object that you can:

  • Define in the MATLAB® base workspace.

  • Derive from a Simulink® block parameter that you define and initialize in a mask.

Use parameters to avoid hard-coding data values and properties. Share Simulink parameters with charts to maintain consistency with your Simulink model.

You can access parameter values in multiple Stateflow® objects in a chart such as states, MATLAB functions, and truth tables. You can include parameters in expressions defining data properties such as:

  • Size

  • Type

  • Initial Value

  • Minimum and Maximum

  • Fixed-Point Data Properties

For more information, see Specify Data Properties by Using MATLAB Expressions

Initialize Parameters from the MATLAB Base Workspace

You can initialize a parameter by defining it in the MATLAB base workspace and in the Stateflow hierarchy.

  1. Define and initialize a variable in the MATLAB base workspace.

  2. In the Stateflow hierarchy, define a data object with the same name as the MATLAB variable.

  3. Set the scope of the Stateflow data object to Parameter.

When the simulation starts, data resolution occurs. During this process, the Stateflow parameter gets its value from the associated MATLAB variable.

Share Simulink Parameters with Charts

You can share a parameter from a Simulink subsystem containing a Stateflow chart by creating a mask for the subsystem.

  1. In the Simulink mask editor for the parent subsystem, define and initialize a Simulink parameter.

  2. In the Stateflow hierarchy, define a data object with the same name as the Simulink parameter.

  3. Set the scope of the Stateflow data object to Parameter.

When the simulation starts, Simulink tries to resolve the Stateflow data object to a parameter at the lowest-level masked subsystem. If unsuccessful, Simulink moves up the model hierarchy to resolve the data object to a parameter at higher-level masked subsystems.

Related Topics