Main Content

Share Parameters with Simulink and the MATLAB Workspace

Parameters are constant data objects that allow flexible configuration for data across your Stateflow® charts and Simulink® models. Use parameters to eliminate hard-coded values and maintain consistency between your charts and Simulink models. Parameters enable you to update multiple data objects simultaneously by changing a single definition. You can create parameters:

  • In the MATLAB® base workspace for variables that charts access by name.

  • From a Simulink block parameters that you define and initialize in a mask and that multiple charts can share.

  • From a data dictionary that you add to the parent Simulink model of the chart. Data dictionaries allow you to use the same parameters throughout your entire model.

Parameter Usage in Charts

You can access parameter values throughout Stateflow objects including states, MATLAB functions, and truth tables. Parameters support expressions that define data properties such as:

  • Size and type specifications

  • Initial value assignments

  • Minimum and maximum bounds

  • Fixed-point data properties

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

Initialize Parameters from the MATLAB Base Workspace

To share consistent values with your chart, use the MATLAB workspace.

To create a workspace parameter:

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

    threshold = 25.5;
    max_iterations = 100;
  2. In the Property Inspector, add a data object with the same name as the MATLAB variable.

  3. Set the Scope property of the Stateflow data object to Parameter.

When the simulation starts, Stateflow resolves the data to connect the chart parameter with the MATLAB variable. Stateflow searches for a MATLAB variable matching the parameter name. The chart parameter then inherits the value from the workspace variable. Name matching is case-sensitive and must match.

If resolution fails, simulation stops with an error message identifying the unresolved parameter.

Share Simulink Parameters with Charts

Simulink masked parameters enable parameter sharing across multiple subsystems containing Stateflow charts.

To create a shared Simulink parameter:

  1. Create a mask for the Simulink subsystem containing your Stateflow chart:

    • Right-click the subsystem and select Mask > Create Mask.

    • In the Parameters & Dialog tab, add mask parameters.

  2. In the Simulink mask editor, define, and initialize parameters. See Mask Editor Overview (Simulink).

  3. In the Stateflow chart hierarchy, add data objects with names identical to the Simulink mask parameter variable names.

  4. Set the Scope property of each Stateflow data object to Parameter.

When simulation begins, Simulink resolves Stateflow parameters using a hierarchical search process. First, Stateflow searches for parameters at the lowest-level masked subsystem containing the chart. If unsuccessful, Stateflow moves up the model hierarchy to higher-level masked subsystems. Stateflow repeats the search process until a matching parameter is found or the top level is reached.

This search process allows charts to inherit parameters from parent subsystems at any level.

Add Data Dictionaries to Charts

Data dictionaries provide centralized parameter management for large models with multiple charts requiring shared constants.

To import a data dictionary:

  1. Import the data dictionary into your Simulink model using Model > Model Properties > Callbacks, or programmatically with:

    Simulink.data.dictionary.open('myDictionary.sldd');
  2. Verify the data dictionary appears in the Model Explorer

    in two locations:

    • Under the Simulink Root component.

    • Inside the chart workspace, under the External Data component.

To use dictionary entries as parameters:

  1. In the Stateflow Symbols pane, add a parameter data object.

  2. Set the parameter Name to exactly match the data dictionary entry name.

  3. Set the Scope to Parameter.

Stateflow uses the dictionary value when the parameter names match exactly.

See Also

Topics