| Contents | Index |
| On this page… |
|---|
This section explains how you create and apply constraints to restrict the test results to a subset of test iterations. You also see how to use a constraint to walk through a set of test results.
Constraints are a Test Results Viewer mechanism that screen out test result values. Constraints can be a single value, a range, or an evaluated expression. Applied constraints result in plots rendered from a subset of test iterations, and the viewer applies constraints immediately to all plots. This is useful when you want to screen out or filter test results in your attempts to find or understand the results of a test.
The Test Results Viewer, when opened after a test run, has constraints present but not applied. The viewer creates a constraint for each test vector and defines the constraint's range as a function of the full range of values in the test vector. These default constraints let you see the immediate effect of your test's test vectors on the results of the test.
For example, the Throttle demo has three test vectors corresponding to changes in damping, mass, and stiffness to a Simulink model. If you display a line plot as explained in Generating Plots, you get a plot similar to the following:

This output shows that the test results group in small clusters. You can use a constraint to see which of the test vectors cause this clustering.
Return the plot to the previous state by clicking the menu next to as and clicking color, then click the Refresh Plot button.
In the Constraints pane, select the check box next to the Damping constraint. The constraint becomes active showing all tests with a Damping greater than or equal to 5.0, which is the lowest value in the range of test vectors. All test results remain in the plot.

Click the right-pointing arrow at the end of the Damping constraint's slider.

This advances the constraints slider by one value of the test vector, which causes the first value of the Damping test vector to be removed from the test results used in generating the plot. The viewer immediately applies this constraint to the plot, which, in this case, removes the left-most cluster of test results from the plot.

The constraint counter gives another way for you to see whether the constraint affected the test results. In this case, if you set the constraint value to 7, the bar shows that there are only 72 of 90 test iterations visible because of the constraint you just created. Thus these 18 test iterations that are screened out have a Damping test vector value greater than or equal to 7 (see Creating a Test Vector to understand test vector values).

The Test Results Viewer lets you create a custom constraint based on the following:
A mathematical expression
Scalar logical test results
Scalar numeric test results
String test results that have a value for each test iteration
Test vectors
You can see an example for creating a constraint based on a mathematical expression in Viewing Test Results.
A constraint you might want to create regularly would isolate test results that have passed or failed. This is useful if your test contains a Limit Check element that assigns data to a test variable that you choose to save as a test result. When this test variable is saved, the SystemTest software records the test iteration and whether the test passed or failed (represented by a 1 or 0); you can create a constraint based on these test results. For example:
If you activated the Damping constraint in Using Default Constraints, deactivate it now by clearing the check box next to Damping, or delete it.
Click the New Constraint button.

The Add a New Constraint dialog box appears.
Click the list beneath the Using a result or test vector field to show the list of test vectors and test results available for basing a constraint on.

Scroll down and select pass_fail in this list. This is the name of the test result that is used to save the Throttle demo's Limit Check element's output.
Click OK. The viewer adds the new constraint to the Constraints pane, but it is not active.
Select the check box next to the pass_fail constraint to apply it.

Change the operator to ==. The value is already set to 0, representing failed test iterations.
You now have a constraint set to show only those test iterations that failed.

If you change the value of the constraint to 1 using the slider, you will show only those test results that passed the Limit Check element in your test.

The constraint option Plot single iteration at a time lets you step through and see individual test results within the subset defined by the active constraints. The plot shows only one test iteration until you choose to show the next or previous one. The specific values for that test iteration's test vectors and test results appear in the Current Iteration pane. This is useful when you want to know what combination of test vectors allow a test to pass, or what values can lead to failure.
For example, if you follow Creating a Constraint, by the end you have created a constraint that shows you all test iterations that have passed. To see each iteration individually:
Move the slider for the pass_fail constraint back to 0.
Select the Plot single iteration at a time check box in the Constraints pane.

The Constraints pane changes to show a slider and the currently displayed test iteration.
Move the slider or click the advance button to see the next iteration. You see only those test results that match any defined constraints, which, in this case includes only those tests that have passed.

The Plots pane updates to show only the plotted line for that iteration.
![]() | Viewing Your Test Results | Viewing Simulink Time Series Data | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |