MATLAB Examples

Overriding Model Parameters in a Test Case

Verify a model against a baseline using a parameter override and the Test Manager. Copyright 2018 The MathWorks, Inc.

Contents

This example shows how to override a parameter defined in a model workspace using the Test Manager and view its effect on model output compared to a baseline.

Open model

mdl = 'sltestParameterOverridesExample';
open_system(mdl);

Open the Test File

Open test manager using the function sltestmgr. Load the example test file named sltestParameterOverridesTestSuite.mldatx using the commands:

exampleFile = fullfile(matlabroot, ...
   'toolbox', 'simulinktest', 'simulinktestdemos', ...
   'sltestParameterOverridesTestSuite.mldatx');
sltest.testmanager.load(exampleFile);

Overriding a Model Parameter

1. Expand the test suite in the Test Browser pane and double-click the test case named Test Override.

2. Scroll down to the Baseline Criteria section and click Capture.

3. Save the baseline file to a convenient location.

4. Expand the Parameter Overrides section in the test case and click Add.

5. In the dialog box, click the Refresh button to display available parameters. Select a.

6. Click OK.

7. The test case displays a in the overrides table. Double-click the Override Value and enter 1.1.

Execution and Results

Select the test file in the Test Browser pane and click Run. In the Results and Artifacts pane, expand the results to see the Baseline Criteria Result and Sim Output.

Select Mux: 1[1] inside Baseline Criteria Result to see how overriding the parameter a affected the mux signal when compared to the captured baseline. The comparison output shows a maximum difference of approximately 0.6.

Overriding Parameters using Data Files

Navigate to the example folder directory:

cd(fullfile(matlabroot,'toolbox','simulinktest','simulinktestdemos'));

1. Return to the test case and scroll to the Parameter Overrides section.

2. Click the Add arrow and select Add File from drop down.

Select the sltestParametersOverrideData.mat file. This file contains data that can be used by the test case to override the parameters.

Select a row, right-click, and select Export. This exports the variable to the MATLAB® base workspace. You can see the value of the variable in the base workspace.

close_system(mdl, 0);
clear mdl;