Main Content

Create and Manage Conditionals

You can use conditionals to monitor when simulation data meets specified criteria and as a trigger for faults. Conditionals use workspace variables, signals, or parameter values to evaluate a Boolean expression. During each major time step, Simscape™ evaluates the conditional after the simulation data is generated. Each fault can use one conditional as the trigger. After simulating models with conditionals, you can view when conditionals trigger in the Simulation Data Inspector.

Create Conditionals

To create a conditional:

  1. Open a model or create and save a new model.

  2. Open the Fault Table pane. Select a Simscape block and, in the Simscape Block tab, in the Faults section, click Fault Table.

  3. In the Conditional tab, click the Create new conditional button .

  4. Modify the properties of the conditional by selecting the conditional and click the Property Inspector button . The properties open in the Property Inspector.

    This image shows the properties of a new conditional in the Property Inspector.

Conditionals evaluate the Boolean expression in the Condition property at each time step. The expression must evaluate to a logical true or false. The conditional triggers the fault when the expression is true.

You can use these MATLAB® operations and functions:

  • Relational operations: >, <, >=, <=, ==, ~=, and ~

  • Logical operations: &, &&, |, and ||

  • Arithmetic operations: +, -, and *

  • MATLAB functions: abs, logical, int8, int16, uint16, int32, uint32, int64, uint64, single, double, and half

For more information, see MATLAB Operators and Special Characters and Logical (Boolean) Operations. The data types in the expression must match, and must be explicitly defined. Using unsupported functions, operators, and inconsistent data types produces an error at compilation.

To retrieve the simulation time at each time step, enter t into the expression. For example, to create a conditional expression that is true where the simulation time is greater than 6, enter t > 6 into the expression.

To save the conditional and updates to its properties, save the model or, in the Fault Table pane, click the Save fault information button . (since R2024a) If you attempt to close the model without saving, Simulink® displays a dialog box that allows you to save the fault information file before closing.

Assign Conditionals to Fault Triggers

To assign a conditional to a fault trigger:

  1. Open the Fault Table pane.

  2. Open the Property Inspector to view the fault properties. In the Fault tab, right-click the fault and click Properties.

  3. Set the Trigger Type property to Conditional.

  4. Set the Select conditional from model property to the conditional.

After you create and assign the conditional to a fault, you can view the conditional assigned to the fault in the Fault Table pane by selecting the fault in the Property Inspector and clicking View conditional.

If you open a conditional in the Property Inspector, the Associated Faults section displays the assigned faults. Click the fault to open the fault properties in the Property Inspector, and click the model element to highlight the model element in the model.

You can adjust how the fault triggers due to the conditional with the Trigger stays on once activated property. If you enable this property, the fault injects when the conditional first satisfies, then continues to inject until simulation ends. If you disable this property, the fault injects only when the conditional expression is satisfied.

Log Conditional Information

When you simulate the model, you can log the conditional trigger status. To log a conditional, in the Fault Table pane, in the Conditional tab, select Log Activity. You can also select the property in the Property Inspector.

When you simulate the model, Simulink records the conditional status as either true or false at the end of each time step. Consequentially, the fault evaluates the state of the conditional in the following time step. You can view the results in the Simulation Data Inspector. To open the Simulation Data Inspector, in the Fault Analyzer tab, in the Review Results section, click Data Inspector. After simulating the model, select the conditional to view the conditional status throughout the simulation.

If you run additional simulations, you can overlay the results by selecting the conditionals in each run and adjusting the layout. For more information on the available layouts, see Inspect Simulation Data.

Delete Conditionals

To delete a conditional, right-click the conditional in the Fault Table pane and select Delete. If the conditional is assigned to a fault, the assigned trigger of the fault reverts back to Always On.

Additionally, deleting the fault information file associated with the model deletes the conditionals. Use this option to permanently delete the model faults and conditionals.