Main Content

Create Data Files for Test Case Input

You can use Test Manager to create MAT-file and Microsoft® Excel® data files to use as inputs to test cases. You generate a template that contains the signal names and the times, and then enter the data.

Creating a data file also adds the file to the list of available input files for the test case. After you add input data, you can then select the file to use in your test case.

You can create files for input data only for tests that run in the current release. To select the release, in the test case, use the Select releases for simulation list.

You can edit input files. After you create the template, select the file from the list of input files and click Edit. MAT-files open in the Signal Editor. Excel files open in Excel.

Selecting the Add an iteration that runs this input check box adds an iteration to the test case under Table Iterations and assigns the input file to it. After you create the input file, continue to specify the iteration. For more information on iterations, see Test Iterations.

Generate an Excel Template

You can generate a template test spreadsheet from a model or harness (system under test [SUT]). You can then complete the spreadsheet with external data and import it into Simulink® Test™ as a test case.

The Create Test from Spreadsheet wizard parses the SUT for test attributes and automatically generates a template spreadsheet and a test case:

  • Inputs — Inputs are characterized by root input ports

  • Parameters — Named parameters in the model

  • Comparison signals — Logged signals and output ports

The wizard allows you to filter and edit the attributes needed for testing. The resulting spreadsheet has separate column sets for inputs, parameters, and comparison signals. If multiple iterations are required, a separate sheet in the same file is generated for each scenario. You can expand the spreadsheet to add time-based signal data, tolerances, and parameter overrides. See Format Test Case Data in Excel for the full description of the format readable by Simulink Test.

You can use the coordinate_transform_test model as an example for the process. Its associated Excel file is coordinate_test.xlsx.

  1. Open the test manager. On the Apps tab, under Model Verification, Validation, and Test, click Simulink Test. Then, on the Tests tab, click Simulink Test Manager.

  2. Open the wizard. From Simulink Test Manager, select New > Test from Spreadsheet. Select Create a test template file for specifying data and follow the prompts.

  3. In the Attributes page, select which attribute categories are to be included in the spreadsheet. For example, if parameter overrides are not necessary for the tests, clear Parameters. The attribute categories shown on the page are derived from the SUT. Comparison signals are always shown.

  4. If the test requires all attributes in a category as is, select Yes, include all attributes in the spreadsheet and click Next. If not, select No, I want to filter and edit the attributes. This shows a page with a tab for each attribute category.

  5. If you are filtering the attributes, in the Parameters and Comparison tabs, clear the attributes that are not needed. For example, you can remove a logged signal from this list if it is not to be used for comparison in the tests.

  6. Optionally change tolerances in the Comparison page. The tolerance settings apply to all signals in the list. To specify different tolerances for each signal, edit the spreadsheet after it is generated.

    Table of signal tolerance settings

    If you change the SUT during the selection process, click Refresh to synchronize the attribute lists with the SUT. Once selection is complete, click Next and keep following the prompts.

  7. In the Scenarios page, specify the number of test scenarios and a base name for the sheets in the spreadsheet.

If comparison signals are selected, the wizard runs the model to capture the baseline. Make sure that the model does not run indefinitely by setting a finite stop time. The wizard creates two files:

  • Excel spreadsheet — The spreadsheet includes columns for inputs, parameters, and comparison signals. Inputs and comparisons have different time bases. An identical sheet for each test scenario is generated. Complete the spreadsheet outside MATLAB® to uniquely define each scenario.

    Excel spreadsheet with time and parameter columns.

  • Test file — The test case imports the Excel spreadsheet. The fields defined in the spreadsheet are locked to the spreadsheet, and cannot be edited in the Test Manager.

    Parameter overrides table

    To change the locked fields, edit the spreadsheet outside MATLAB.If you change a parameter, you must capture the baseline again by clicking the Capture button.

    Baseline criteria table

Format Test Case Data in Excel

You can specify signal data in a Microsoft Excel file to use as input to your test case or as baseline criteria (outputs). The Excel file includes time and signal data. To support a range of models and configurations, you can specify signal data of most data types. You can indicate whether signals are scalar, multidimensional, or complex. You can optionally specify the data type, block path and port index, units, interpolation type, and function-call execution times.


For information on how to format data in Excel files, see Microsoft Excel Import, Export, and Logging Format.

Additional information specific to test cases includes:

  • Importing the file as input data — Use the Inputs section of the test case, described in Use External Excel or MAT-File Data in Test Cases.

  • Using the Excel file as expected outputs — Select the file to add it as baseline data, in the Baseline Criteria section of the test case, described in Baseline Criteria. For more information, see Multiple Runs.

  • Capturing inputs and expected outputs in Test Manager — Save inputs and outputs to the same Excel file. Both sets of data are saved to the same sheet unless you specify a different sheet. Saving the inputs or expected outputs adds the file to the test. See Capture Baseline Criteria.

  • Specifying tolerances — See Compare Model Output to Baseline Data.

Create a MAT-File for Input Data

  1. In the test case, under System Under Test, specify the model whose input data you want to create a MAT-file for.

  2. In the Inputs section of the test case, click Create.

  3. In the dialog box, set the file format to MAT-file. Specify the location for the MAT-file and click Create.

    The Signal Editor opens.

  4. In the Scenarios and Signals pane of the Signal Editor, expand the data node. Then select the signal whose data you want to add.

  5. Specify the signal data. Select the data type from the list, and enter the time and signal data for the signal.

    Signal editor with inputs options.

  6. To update your signal data, click Apply.

  7. After adding the signal data, click Save.

See Also


Related Topics