Main Content

Use Parameters to Store Instance Values with Components

This example shows how to add value types as model arguments to a System Composer™ architecture model of a wheel, mWheelArch.slx, using the Model Explorer. Then, on the System Composer architecture model mAxleArch.slx, these model arguments are exposed as instance-specific parameter values that can be changed independently across each component that references mWheelArch.

Use Model Explorer to Add MATLAB Variables as Model Arguments

Open the mWheelArch model.

systemcomposer.openModel("mWheelArch");

Navigate to Modeling > Model Explorer or enter Ctrl+H. The Model Explorer opens. Expand the mWheelArch model and select Model Workspace. View the contents of the model workspace. The workspace contains three Simulink Parameters named Diameter, Pressure, and Wear.

2022-01-11_11-28-45.png

To add a new MATLAB® variable to the model workspace, on the toolstrip menu, click icon.png. You can rename your variable from the default name Var and set its starting value. If you select the Argument check box, the MATLAB variable becomes a model argument. As a model argument, the variable can later be exposed as an instance-specific parameter value in an architecture model. Rename the variable to TreadDepth and set its value to 1, then select it as a model argument.

2022-01-11_11-31-21.png

Use Model Explorer to Add Simulink Parameters as Model Arguments

In the Model Explorer, you can also add Simulink® parameters as model arguments. To add a new Simulink parameter to the model workspace, on the toolstrip menu, click simu.png. You can edit the attributes of a Simulink parameter including: Name, Value, DataType, Dimensions, Complexity, Min, Max, and Unit. These attributes contribute to the parameter definition when the parameter is specified as a model argument. Select the Argument check box to specify a parameter as a model argument. Rename the variable to PressureBar, set its value to 2000, set its units to mbar, then select it as a model argument.

2022-01-11_11-33-57.png

Right-click the mWheel model in the Model Explorer. Save these changes to the model workspace, then close the Model Explorer.

View and Edit Parameters on Components in Architecture Model

Open the mAxleArch architecture model.

systemcomposer.openModel("mAxleArch");

Select the LeftWheel component that references the mWheel model. The parameters appear on the Property Inspector with default values.

2022-01-18_9-29-09.png

You can expose these parameters as model arguments and then edit the parameters as instance-specific parameters independently for each component that references the same model. Right-click the RightWheel component and select Block Parameters (Model Reference). Click the Instance parameters tab and select the Argument check box for the new parameters Pressure and TreadDepth.

2022-01-11_11-36-15.png

Once selected, these parameters are treated as model arguments of the mAxleArch model and can be changed independently for each instance the model.

Edit the parameters for the RightWheel component so that Pressure and PressureBar are now 31 psi and 2100 mbar, respectively.

2022-01-18_9-30-20.png

The corresponding parameter values for the LeftWheel component remain unchanged.

See Also

| | | | | | | | | |

Related Topics