Share Parameters with Simulink and the MATLAB Workspace - MATLAB & Simulink (original) (raw)

Main Content

A parameter is a constant data object that you can:

Use parameters to avoid hard-coding data values and properties. Share Simulink parameters with charts to maintain consistency with your 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:

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 .

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

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 .

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.

Add Data Dictionaries to Charts

To add a data dictionary to a Stateflow chart, import the data dictionary into the Simulink model that contains the chart. The data dictionary appears in multiple locations in the Model Explorer:

  1. Under the component.
  2. Inside the chart workspace, under the component.

For instructions on importing a data dictionary into a model, see Import and Export Dictionary Data (Simulink).

To read an entry from an imported data dictionary, add the entry to the pane as a parameter. The entry and parameter must have identical names. For instructions, see Add Stateflow Data.

See Also

Topics