|On this page…|
The examples in Configuration of a Simulink Element described how to override block parameters and workspace variables. Similarly, you can override signals to root-level Inport blocks in Simulink with SystemTest™ data.
Because the Simulink element uses the Inport block names, not the port numbers, your test works even if you reorder the Inport blocks in the model.
Some users store signal values in a Microsoft® Excel® spreadsheet or .csv file. You can create a test vector that reads values from a spreadsheet and use that as your Inport block signal mapping. The Override Simulink Inport Blocks Using a Spreadsheet Data Test Vector section shows such a scenario.
You can also store signal values in a MAT-file and then create a test vector that reads the values from the MAT-file. The Map Logged Signals from a Model to Inport Blocks section shows this scenario.
To override Inport block signals:
If you have a model that contains Inport blocks and you have created a Simulink element that uses that model, click the Mappings tab inside the Simulink element.
Expand the Override Inport Block Signals with SystemTest Data section by clicking the expander arrow on the right side of the section title.
Designate your mappings.
The user interface indicates how many Inport blocks your model contains. For example, the model used in the Simulink Input example contains three Inport blocks, as shown here. You can open this example by typing the following in the MATLAB® command line:
The first option, Do not override Inport block signals, is selected by default. That means the test will run the model without modifying any Inport block settings. Any data the Inport blocks are configured to use will be used during execution. If you want to override the model, use one of the other two options.
The All Inport blocks are mapped using option allows you to map data to all Inport blocks at once. Use the drop-down list to choose an existing test vector or test variable, or to create a new one. This supports any data format the Simulink® model supports. For example, it could be a test vector that is an array of time and three signal values, such as [time, U1, U2, U3].
If you want to map individual Inport blocks, select the Individual Inport blocks are mapped using option.
When you select this option, the mapping table becomes editable. In the case shown here, In1 and In2 are being overridden with SystemTest data, and In3 is using the value in the model.
The table displays all Inport blocks contained in the model. By default, the SystemTest Data column is assigned as Inherit from model. This is especially convenient if you have a large number of Inport block signals and only want to override a small number of them in your test. You would just change the SystemTest Data column value for the ones you want to override.
You can update the list of Inport blocks that are displayed in the table by clicking the Open and update model state button in the Simulink element. The Inports listed in the table are sortable.
Note: If you open a TEST-File and do not see the Inport blocks from your model reflected in the Simulink element, click the Open and update model state button:
to populate the Inport table.
Note: If you have variables in a Spreadsheet Data test vector or a MAT-File test vector, you can optionally use the Mappings Assistant. Click the Mappings Assistant button above the table. For more information on using the Mappings Assistant, see Inport Block Mappings Assistant.
If you are using the map all option or individual mappings, you need to define the test signal time and the end time. If you are using the inherit from model option, skip this step since the time options do not apply to inherited mappings.
In the Define test signal time option, you can specify the simulation time signal to provide to the model. To specify the time signal using a test vector or test variable, select Map test signal time to. To specify a time signal based on a desired simulation time step, select Manually specify a time step and then enter a valid time step, which must be a positive number.
In the To calculate end time of simulation option, either use the model's stop time, or use the signal's end time based on the time step you specified. The Use model stop time option stops the simulation of the model at the end time configured in the model. The Use signal's end time option stops the simulation of the model at the end of the test signal, temporarily overriding the end time of the model with the test signal end time.
If you are overriding Inport block signals, as shown in Override Inport Block Signals in a Simulink Element, then you can optionally use the Mappings Assistant when you use the Individual Inport blocks are mapped using option.
When overriding Inport block signals, select the Individual Inport blocks are mapped using option.
Click the Mappings Assistant button above the table. This button is only available when you are configuring individual mappings.
In the Inport Block Mappings Assistant dialog box, choose your mapping in the Override each Inport block using section.
If you are using a Spreadsheet Data test vector, select the A spreadsheet test vectors headers option. Then in the drop-down list, select an existing Spreadsheet Data test vector, or create a new one.
If you are using a MAT-File test vector, select the A MAT-File test vectors selected variables option. Then in the drop-down list, select an existing MAT-File test vector, or create a new one.
If you have a test variable whose name matches the Inport block, select the An existing test variable with a matching name option.
The If an Inport block name cannot be matched section determines what happens in the case of one or more variables in the selected test vector not matching an Inport block name. Select the option you want the Simulink element to perform. Inherit from Model is the default.
The Summary section displays information on how many root-level Inport blocks are found in the model, how many are mapped to the test vector you selected if you are mapping from a test vector, and how may will use the option you chose in step 4 in the case of non-matches.
When you are finished configuring the mappings and viewing the summary, click OK to create the mappings.
The mappings are then displayed in the table.
In this example, a Simulink element is being used to test a model of a fuel rate controller. To see the test and the model, open the example by typing the following at the MATLAB command line:
The model has four Inport blocks that represent throttle angle, engine speed, exhaust gas, and manifold pressure.
The tester has values for these four blocks in a Microsoft Excel spreadsheet. It contains 37 sets of generated values for the blocks. Each set of values is on a different sheet within the spreadsheet, representing a testing scenario for the model. One of the sheets is shown here.
Column A represents the simulation time signal. Columns B through E represent test data for the four Inports in the model. Each of the 37 sheets is set up the same way but contains different values.
To set up the test vector that reads the data from the spreadsheet:
Create the test vector by clicking the New button in the Test Vectors pane.
In the Insert Test Vector dialog box, select Spreadsheet Data as the vector type.
On the General tab, name the test vector InputSignal.
Click the Add File button and browse to the Microsoft Excel spreadsheet.
Click the Select All button to select all sheets in the spreadsheet file.
On the Data Selection tab, keep the default of column in the Data is arranged by option.
In the Read data from column option, enter A to E, starting at row 1.
Select the First row is a header option, since you can see in the above figure of the spreadsheet that row 1 of the file contains text labels.
Select the Treat each selected sheet as a test vector value option.
The configured test vector appears as follows.
Click OK in the Insert Test Vector dialog box.
The new vector appears in the table in the Test Vectors pane. You can see that the length is 37 because there are 37 sheets in the spreadsheet file and each sheet is being treated as one value in the vector.
Now that the test vector is set up, you can set up the Simulink element to override the Inport blocks using the test vector values from the underlying spreadsheet file.
Create a Simulink element by clicking New > Test Element > Simulink button in the Test Browser.
Click the browse button to locate the Fuel Rate Controller model.
On the Mappings tab, expand the Override Inport Block Signals with SystemTest Data section if it is not open.
Select the Individual Inport blocks are mapped using option. The four Inport blocks appear in the table.
For each Inport block, use the drop-down list in the SystemTest Data column to override the Inport block with the appropriate data in the test vector that was created earlier.
For example, for throttle, click the drop-down list, expand the InputSignal test vector entry, and select throttle. Do the same for the other three signals.
The entries under the InputSignal test vector represent the underlying columns in the spreadsheet. Since the Spreadsheet Data test vector called InputSignal was created using the columns and the headers, the columns appear named with their headers in the list for easy identification, for example, InputSignal(throttle).
In the Define test signal time option, select Map test signal time to and choose InputSignal(Time).
Time is the first column in the spreadsheet and contains the simulation time signal for the model. The test will use these time step values when the Simulink element is executed.
Select the Use signal's end time option, so that the end times provided in the spreadsheet are used.
The configured Simulink element appears as follows.
When the test is executed, the Simulink element will test the model using the Inport block signals mapped from the spreadsheet.
You can map logged signals from a Simulink model, including bus signals, to Inport blocks of a model using the Simulink element and a test vector or test variable that contains the logged signal data.
A common usage scenario is to log the signals while running a model and store them in a MAT-file. Then you can acquire them from the Mat-file using a MAT-File test vector and map that data to Inport blocks in the Simulink element. The following high-level steps outline this usage scenario.
Do one of the following:
Run your model that contains signals. The signals are logged as variables in the MATLAB workspace. Save the variables as a MAT-file.
Alternatively, use MAT-file(s) that have already been created and saved.
In the SystemTest software, create a MAT-File test vector using the MAT-file that your signals are saved in. See MAT-File Test Vectors for more information on MAT-File test vectors.
Add a Simulink element to your test, and select the model that you want to test.
In the Override Inport Block Signals with SystemTest Data section, select the All Inport blocks are mapped option.
From the drop-down list, select the MAT-File test vector you created, and drill down into the variable that represents the signal you want to use. This is how you map the logged signals to the Inport blocks.
Note that the logged signal(s) and the Inport block(s) must have exactly the same name(s) for the Simulink element to simulate the model successfully. See the usage notes below.
Run the test.
Important Usage Notes
– The logged signal(s) and Inport block(s) must have identical names that match exactly. To use this feature, each Inport block name must match a corresponding signal name within the logged data. If it does not, you can rename the Inport block or the signal in the logged data to avoid an error. You can have other signals in the logged data, but each Inport block must exactly match a signal name.
– The following data types are supported: