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, Simulink® Fault Analyzer™ 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. In the Fault Analyzer tab, in the View 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.

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 save the conditional and updates to its properties, save the model. 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 Symbols to Expressions or Model Elements

When you first use a symbol in an expression, the software does not recognize the value. You assign the symbol values manually in the Symbols table. In the Symbols table, double-click the cell in the Mapped To column to choose the symbol assignment type. You can set Mapped To to Expression or Model Element.


Symbols must evaluate to a real scalar.

If you select Expression, you must set the Value cell to a variable defined in the model workspace or base workspace, or to a real scalar. See Specify Source for Data in Model Workspace.

If you select Model Element, the model opens bind mode. To select the model element, click a signal and select a model element. You can select one block output signal per symbol. Exit bind mode by clicking the exit icon in the top-right corner of the model canvas. The Value column shows the path of the selected model element.

The Symbols pane after a symbol has been mapped to a model element. The Value column shows the path of the model element, and the path name is blue.

Clicking the Value cell highlights the associated signal in the model.

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 each 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.

This image shows an example of the conditional as it appears in the Simulation Data Inspector after a 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.

Investigate an Example Model with a Conditional

This example uses a fault with a conditional that triggers based on the value of a workspace variable.

Open the fault_conditional_exp model. The model uses a callback to define the workspace variable K. You can modify the model callback by opening the Model Properties window. In the Modeling tab, click Model Settings > Model Properties. In the Model Properties window, open the Callbacks tab and click PreLoadFnc in the left pane.

Open the Conditional

Open the conditional properties in the Property Inspector. In the Fault Analyzer tab, in the View section, click Fault Table. In the Fault Table pane, in the Conditional tab, right-click the conditional and select Properties. The conditional uses two symbols, signalVal and const_K. const_K is assigned to the workspace variable K. signalVal is assigned to the value of the Sine Wave block output port. The Condition Expression property defines the relationship between the two symbols. If the absolute value of the signal from the Sine Wave block is greater than K, then the condition is true and the fault triggers.

Simulate the Model

Simulate the model. The fault triggers when the conditional is satisfied, which overwrites the signal from the Sum block output to 0. Open the Scope block to view the model behavior.

You can view the conditional and fault injection status during simulation in the Simulation Data Inspector. Open the Simulation Data Inspector and select the conditional and fault to view the statuses at each major time step.

The fault evaluates the state of the conditional before the conditional evaluates. As a result, the fault injects in the time step that follows from the time step where the conditional signal_greater_than_val is true.

Related Topics