Share Parameters with Simulink and the MATLAB Workspace - MATLAB & Simulink (original) (raw)
Main Content
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.
- Derive from a data dictionary that you add to the parent Simulink model of the chart.
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:
- 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.
- Define and initialize a variable in the MATLAB base workspace.
- In the Stateflow hierarchy, define a data object with the same name as the MATLAB variable.
- 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.
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.
- In the Simulink mask editor for the parent subsystem, define and initialize a Simulink parameter.
- In the Stateflow hierarchy, define a data object with the same name as the Simulink parameter.
- 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:
- Under the component.
- 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.