| Contents | Index |
| On this page… |
|---|
Override Simulink Model Inputs Map Simulink Model Outputs to Test Variables |
To help you learn how to use the Simulink element, this section walks you through the configuration of the Simulink element for the Inverted Pendulum test. The Inverted Pendulum demo includes both a model of the pendulum and a model of a controller that keeps the inverted pendulum balanced. Moving the bottom of the pendulum disturbs the equilibrium, causing the pendulum to move and the controller to rebalance it. The Inverted Pendulum test varies the mass of the pendulum, the mass of the cart the pendulum is on, and the distance to the pendulum's center of mass, testing the robustness of the controller as it attempts to return the pendulum to equilibrium. Using the Simulink element in a test lets you vary the model inputs and assess the model outputs.
Note The following sections assume you have loaded the Inverted Pendulum demo and deleted the Simulink element, as explained in Before You Begin. |
To add a Simulink element to a test, click the New > Test Element button in the Test Browser and select the Simulink element. If you have a license for Simulink, the element list contains the Simulink element, as shown in the following figure.

The SystemTest software adds the Simulink element to the test and opens the Simulink element Properties pane.

When you first add the element, the icon in the Test Browser has a red x, meaning that the element requires some information. The Simulink model field in the Simulink element Properties pane is outlined in red, indicating that it is a required field. You must specify the model that the Simulink element will interact with. If the model is on the MATLAB path, you can type its name in the Simulink model field. If you are not sure of the name, or the model is not on the path, you can browse to its location using the browse button.
For the Inverted Pendulum example, type systemtestpendulum in the Simulink model field and press Enter. The SystemTest software opens the systemtestpendulum model in Simulink and opens the Pendulum Visualization window.
Using test vectors and test variables, you can override the following Simulink model inputs:
Block parameters — Described in Override Simulink Block Parameters
Model and base workspace variables — Described in Override to Workspace Variables
Inport signals — Described in Override Simulink Model Inport Signals
You can override Simulink block parameters with SystemTest test vectors or test variables. When you run the test, Simulink runs the model using data provided by the SystemTest software. Overriding does not change your Simulink model file; it only overrides in the test. The procedure for creating block parameter overrides requires that you select your block in the Simulink model, but everything else you need to do happens within the Simulink element Properties pane.
To override a Simulink block parameter:
In the Mappings tab of the Properties pane for the Simulink element in the SystemTest software, expand the Override Block Parameters with SystemTest Data section and click the New Mapping button, and select Select Block to Add. This opens the model in Simulink, if it is not already open.
In the Simulink model window, click the block containing the parameter you want to override. For this example, click the Pendulum block in the systemtestpendulum model window.
In the SystemTest software, return to the Simulink element Properties pane and, in the Override Block Parameters section, you'll see that the Pendulum was added. If you click the New Mapping button again, you'll see that the SystemTest software also adds an entry to this menu for the block.

In the override table, the Simulink Data field shows that this entry is linked to the Pendulum block but the question mark (?) indicates that no parameter for the block has been mapped.

Select the parameter from the block that you want to map. Click the Simulink Data field for the block and select a parameter from the list. For the Inverted Pendulum demo example, select Pendulum:Mass of cart (kg).
Specify the SystemTest test vector or test variable you want to map to this block parameter. Click the SystemTest Data field for the block parameter. This shows you all defined SystemTest test vectors and test variables available for mapping. For this example, select cart.

You can use a SystemTest test vector or test variable to override either a MATLAB base workspace variable or a Simulink model workspace variable. This lets you define test values and conditions in the SystemTest software and have a Simulink model act on them.
This section describes how you can use the values in the pend and distance test vectors to override the model workspace variables masspend and penddistance in the Inverted Pendulum demo.
To override workspace variables:
Expand the Override MATLAB and Model Workspace Variables with SystemTest Data area of the Simulink element Properties pane, and click the New Mapping button.
Select the workspace variable you want to override. Click the Simulink Data field of this row to see all available base workspace variables and Simulink model workspace variables. For the Inverted Pendulum example, select masspend.

Specify which SystemTest test vector or test variable you want to map to the Simulink workspace variable. Click the SystemTest Data field of this row to see all available test vectors and test variables. For this example, select pend.

Repeat steps 1 to 3 to override the Simulink model workspace variable penddistance with the SystemTest test vector distance.

As with block parameters and workspace variables, you can use the SystemTest software to override a model's inport signals. This lets you externally manipulate the input signal of a Simulink model.
The Inverted Pendulum demo example does not override any inport signals.
For information on how to override inport signals and an example, see Override Inport Block Signals.
Optimizing Test Vectors to Work with Inport Signals
Simulink allows you to import input signal and initial state data from the MATLAB workspace and export output signal and state data to the MATLAB workspace during simulation. In the SystemTest software, you can specify the contents of a test vector so that it is used as a Simulink inport. To do that, use the vector as the mapping in your Simulink element, by selecting it in the SystemTest Data row as described above.
The Simulink documentation contains guidance on importing data to Simulink inport signals. You can create the same type of data in your SystemTest test vectors that you then map to inport signals. For more information on appropriate data types, see Importing and Exporting Simulation Data in the Simulink documentation.
Example for Overriding Inport Signals Using Data Arrays
One of the data formats described in Importing and Exporting Simulation Data in the Simulink documentation is the use of data arrays for specifying input data to an Inport block. This example uses the systemtestinputdemo.mdl model to illustrate how the SystemTest software can be used to override the three Inport blocks in the model with test signals.
The first step involves constructing a test vector that specifies the different signal test cases. This can be done by creating a MATLAB function that simply returns a test vector containing the different test cases you would like to use for each test iteration. A sample MATLAB function, called GETTESTVECTOR, that does this is provided below.

Once this function is saved as GETTESTVECTOR, you can create a SystemTest test vector whose expression is set to GETTESTVECTOR. This will create a 1-by-3 test vector cell array within the SystemTest software, where each entry in the cell array represents the time and signal data for the three Inport blocks.
For detailed information on the Simulink data array format, or other formats supported by Simulink Inport blocks, see Importing and Exporting Simulation Data in the Simulink documentation.
Using test variables you can assign the output from the following types of Simulink model data:
Logged signals — Described in Map Simulink Logged Signals to Test Variables
Outport signals — Described in Map Simulink Outport Signals to Test Variables
To Workspace blocks — Described in Map Simulink To Workspace Blocks to Test Variables
After you map model outputs to test variables, you can incorporate the model data into the SystemTest software. This section shows you how to map this data for the Inverted Pendulum example.
Note The output from Simulink models can only be mapped to SystemTest test variables. You cannot map this output to SystemTest test vectors. |
Note If you are mapping logged signals, outport signals, or To Workspace blocks to test variables, as shown in the following procedures, then you can optionally use the Mappings Assistant if you want the variables to have the same names as the inputs. This is useful if your model contains many signals or blocks and you want to name the outputs the same way. You no longer have to create test variables with matching names manually. See Model Output Mappings Assistant for more information. |
Logged signals are a way to obtain outputs from a model without adding more outports. Using logged signals, you can identify a particular signal and map the output to a SystemTest test variable.
To map logged signals to a SystemTest test variable:
Expand the Assign Model Outputs to SystemTest Data section of the Simulink element Properties pane, and click the New Mapping button. From the list, select Logged Signal. The SystemTest software adds a row for a new mapping of this type.

Specify the signal you want to capture. Click the Simulink Data field to see all the signals in the model. For the Inverted Pendulum example, select pendout.
Note If you added logged signals to your model and they do not appear in this list, click the refresh button, on the Properties pane next to the model name, to update the list. |

Specify the SystemTest test variable to which you want to map the output. Click the SystemTest Data field and select a test variable. For the Inverted Pendulum example, select st_loggedsignal.

The SystemTest software creates the mapping to the test variable.

Note If you are mapping logged signals to test variables, as shown in the above procedure, then you can optionally use the Mappings Assistant if you want the variables to have the same names as the inputs. This is useful if your model contains many signals or blocks and you want to name the outputs the same way. You no longer have to create test variables with matching names manually. See Model Output Mappings Assistant for more information. |
The SystemTest software lets you map all outport signals to a test variable for further processing in the SystemTest software.
To map Simulink outport signals to a test variable:
In the Assign Model Outputs to SystemTest Data section of the Simulink element Properties pane, click the New Mapping button. From the list, select Outport Signal. The SystemTest software adds a row for a new mapping of this type.
Specify the outport signal you want to capture. Click the Simulink Data field and select a signal. For this example, select Out1.

Specify the SystemTest test variable to which you want to map the outport signals. Click the SystemTest Data field and select a test variable from the list. For this example, select st_outportsignal.
The SystemTest software creates the mapping to the test variable.

Note If you are mapping outport signals to test variables, as shown in the above procedure, then you can optionally use the Mappings Assistant if you want the variables to have the same names as the inputs. This is useful if your model contains many signals or blocks and you want to name the outputs the same way. You no longer have to create test variables with matching names manually. See Model Output Mappings Assistant for more information. |
When Simulink runs a model with To Workspace blocks, these blocks save model information in the MATLAB workspace as variables. Using the SystemTest software, this data can be mapped to SystemTest test variables.
This section shows how you create To Workspace block mappings in the SystemTest software using the Inverted Pendulum demo as an example.
To map the To Workspace block:
In the Assign Model Outputs to SystemTest Data section of the Simulink element Properties pane, click the New Mapping button. From the list, select To Workspace Block. The SystemTest software adds a row for a new mapping of this type.
Specify the To Workspace block in the model that you want to capture. Click the Simulink Data field and select the block from the list. For this example, select To Workspace.

Specify the SystemTest test variable to which you want to map the To Workspace block. Click the SystemTest Data field and select a test variable from the list. For this example, select New Test Variable to create a test variable.

The SystemTest software opens the Edit Variable dialog box. Assign a name to the test variable and optionally an initial value, and then click OK. Name the test variable ToWSResult.

The SystemTest software creates the mapping to the new test variable and adds the new test variable to the list in the Test Variables pane.

Note If you are mapping To Workspace blocks to test variables, as shown in the above procedure, then you can optionally use the Mappings Assistant if you want the variables to have the same names as the inputs. This is useful if your model contains many signals or blocks and you want to name the outputs the same way. You no longer have to create test variables with matching names manually. See Model Output Mappings Assistant for more information. |
If you are mapping logged signals, outport signals, or To Workspace blocks to test variables, for example in the procedures in the above section Map Simulink Model Outputs to Test Variables, then you can optionally use the Mappings Assistant if you want the variables to have the same names as the inputs. This is useful if your model contains many signals or blocks and you want to name the outputs the same way. You no longer have to create test variables with matching names manually. Using the Mappings Assistant is the preferred method of setting up mappings since it is easier.
In the Assign Model Outputs to SystemTest Data section of the Simulink element, click the Mappings Assistant button above the table.
In the Model Output Mappings Assistant dialog box, choose your mapping(s) in the Create mappings for each section.
If your model contains any logged signals, the Logged Signals option is available. Select the option to map the logged signal(s) to test variable(s). If the model contains no logged signals, this option is disabled.
If your model contains any outport signals, the Outport Signals option is available. Select the option to map the outport signal(s) to test variable(s). If the model contains no outport signals, this option is disabled.
If your model contains any To Workspace blocks, the To Workspace Blocks option is available. Select the option to map the block(s) to test variable(s). If the model contains no To Workspace blocks, this option is disabled.
Click OK to create the mappings.
The Simulink Data column then displays the names of the logged signals, outports, or To Workspace blocks that the model contained. The SystemTest Data column displays the test variables created with the same name.
For example, if the model contains two outports called Out1 and Out2, the Simulink Data column displays Out1 and Out2, and the SystemTest Data column displays Out1 and Out2 to represent the test variables that were created.
If you want to edit a test vector or test variable while working in the Simulink element, you can open the appropriate editor by right-clicking on the name of the test vector or test variable in any of the tables on the Mappings tab.
![]() | Before You Begin | Override Inport Block Signals | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |