This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Use External Inputs in Test Cases

You can use external model inputs from MAT-files or Microsoft® Excel® files in a test case. When you add the file, you can select one of these mapping modes to specify the model element to map to:

  • The names of the inport block the signal data corresponds to

  • The full block path name, that is, in the form system/block

  • The name of the signal associated with the inport block

  • Port number, that is, sequential port numbers of the inport blocks, starting at 1

You can add multiple external input files to a test case. After you add the files, select the one you want to use in the test case from the External Inputs table. If you are using test iterations, you can assign one input file to each iteration.

For more information about how Simulink® handles inport mapping, see Map Root Inport Signal Data (Simulink).

Mapping Status

When you map external inputs to model elements, the mapping can create these possible results. These results appear under Inputs in the Test Manager interface in the Status column:

  • Mapped — The mapping succeeded and no further action is needed.

  • Failed — The mapping failed. Click the Failed link for more information.

  • Warning — The mapping occurred with warnings. Click the Warning link to see whether you need to address them

  • Stale — This status can occur when you update your external inputs in Test Manager. A stale state occurs if you did not map the new inputs. To address this status, click the Status link, which opens the Add Input dialog box. Click Map Inputs to map the new input data and then click Add.

Add a MAT-File as an External Input

  1. In the test case, expand the Inputs section and click Add.

  2. Browse to the MAT-file and click Add.

  3. Under Input Mapping, choose a mapping mode.

  4. Click Map Inputs. The Mapping Status table shows the port and signal mapping.

    For information about troubleshooting the mapping status, see Understand Mapping Results (Simulink).

  5. Click Add.

Add Microsoft Excel File as Input

You can import Microsoft Excel spreadsheets to use as inputs. You can import multiple sheets at once and specify a range of data. Selecting sheets and specifying ranges is useful when each sheet contains a different data set or the same file contains input data and expected outputs.

For information about the Excel file format, see Specify Microsoft Excel File Format for Signal Data.

  1. In the test case, expand the Inputs section and click Add.

  2. Browse to your Microsoft Excel file and click Add.

  3. Select each sheet that contains input data. You can specify a range of data.

  4. If you want to use each sheet to create an input set in the table, select Create scenarios from each sheet.

  5. Under Input Mapping, select a mapping mode.

  6. Click Map Inputs. The Mapping Status table shows the port and signal mapping.

    For more information about troubleshooting the mapping, see Understand Mapping Results (Simulink).

  7. Click Add.

Importing Microsoft® Excel® Data

Test a model using inputs stored in Microsoft Excel.

This example shows how to create a test case in the Test Manager and map data to the test case from a Microsoft® Excel® file. Input mapping supports Microsoft Excel spreadsheets only for Microsoft Windows®.

Create a Test File

1. Open the Test Manager. Enter


2. In the test manager toolbar, select New > Test File. Save the file to a writable directory. The test manager creates a test file with an empty baseline test case.

3. In the test browser, select the test case. In the test editor, under the System Under Test section, enter sltestExcelExample.

Configure the External Inputs.

1. Expand the Inputs section of the test case.

2. To include the input data in the test results, click Include external inputs/signal builder data in test result.

3. Under the External Inputs table, click Add.

4. In the Add Input dialog box, for File, select the sltestExampleInputs.xlsx from the matlab/toolbox/simulinktest/simulinktestdemos directory.

5. In the Add Input dialog box,

  • Select the Acceleration sheet from the sheets table.

  • Select Mapping Mode : Block Name.

  • Click Map Inputs.

  • Click Add.

The Mapping Mode controls the method used to map data from the Microsoft Excel sheet to root-level Inport blocks in the model. For more information, see Use External Inputs in Test Cases.

The test case shows the inputs mapped.

Run the Test

1. In the toolbar, click Run.

2. In the Results and Artifacts pane, you can plot signals from the external inputs or the simulation output.

See Also

Related Topics