Documentation Center

  • Trial Software
  • Product Updates

Override Inport Block Signals

Introduction

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.

Override Inport Block Signals in a Simulink Element

To override Inport block signals:

  1. 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.

  2. Expand the Override Inport Block Signals with SystemTest Data section by clicking the expander arrow on the right side of the section title.

  3. 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:

    systemtest SimulinkInputDemo1

    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.

  4. 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.

      Note:   The Define test signal time option and the To calculate end time of simulation option are disabled if all individual Inport mappings are set to inherit from the model.

Inport Block Mappings Assistant

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.

  1. When overriding Inport block signals, select the Individual Inport blocks are mapped using option.

  2. Click the Mappings Assistant button above the table. This button is only available when you are configuring individual mappings.

  3. 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.

  4. 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.

  5. 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.

Override Simulink Inport Blocks Using a Spreadsheet Data Test Vector

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:

systemtest('demosystest_fuelctrlsldv.test');

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:

  1. Create the test vector by clicking the New button in the Test Vectors pane.

  2. In the Insert Test Vector dialog box, select Spreadsheet Data as the vector type.

  3. On the General tab, name the test vector InputSignal.

  4. Click the Add File button and browse to the Microsoft Excel spreadsheet.

  5. Click the Select All button to select all sheets in the spreadsheet file.

  6. On the Data Selection tab, keep the default of column in the Data is arranged by option.

  7. In the Read data from column option, enter A to E, starting at row 1.

  8. 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.

  9. Select the Treat each selected sheet as a test vector value option.

    The configured test vector appears as follows.

  10. 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.

  1. Create a Simulink element by clicking New > Test Element > Simulink button in the Test Browser.

  2. Click the browse button to locate the Fuel Rate Controller model.

  3. On the Mappings tab, expand the Override Inport Block Signals with SystemTest Data section if it is not open.

  4. Select the Individual Inport blocks are mapped using option. The four Inport blocks appear in the table.

  5. 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).

  6. 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.

  7. 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.

Map Logged Signals from a Model to Inport Blocks

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.

  1. 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.

    OR

    Alternatively, use MAT-file(s) that have already been created and saved.

  2. 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.

  3. Add a Simulink element to your test, and select the model that you want to test.

  4. In the Override Inport Block Signals with SystemTest Data section, select the All Inport blocks are mapped option.

  5. 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.

  6. 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:

  • Simulink.Timeseries.

  • Simulink.TsArrays.

  • Simulink.SubsysDataLogs.

Edit a Test Vector or Test Variable from within the Element

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.

Was this topic helpful?