Main Content

Simulink.fault.addFault

Add fault to model

Since R2023b

Description

fault = Simulink.fault.addFault(modelElement) adds a fault to the model element input or output port, modelElement.

example

fault = Simulink.fault.addFault(modelElement,Name=Value) specifies additional properties for a fault using one or more name-value arguments.

example

Examples

collapse all

Open a model with a block that supports fault modeling.

openExample('simscape_shared/SimpleMotorArmatureWindingFaultExample')

Add a fault to the Armature winding model subelement in the DC Motor block.

Simulink.fault.addFault(...
"SimpleMotorArmatureWindingFault/DC Motor/Armature winding")
ans = 

  Fault with properties:

            Name: 'DCMotor_fault'
     Description: ''
    ModelElement: 'SimpleMotorArmatureWindingFault/DC Motor/Armature winding'
            Type: 'Simscape'
        IsActive: 0

Open a model with a block that supports fault modeling.

openExample('simscape_shared/SimpleMotorArmatureWindingFaultExample')

Add a fault named myFault to the Armature winding model subelement in the DC Motor block.

Simulink.fault.addFault(...
"SimpleMotorArmatureWindingFault/DC Motor/Armature winding",...
Name="myFault")
ans = 

  Fault with properties:

            Name: 'myFault'
     Description: ''
    ModelElement: 'SimpleMotorArmatureWindingFault/DC Motor/Armature winding'
            Type: 'Simscape'
        IsActive: 0

Input Arguments

collapse all

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Example: Name="new_fault_1"

Name of the fault, specified as a string scalar or character vector. If you do not specify this argument, then the name is automatically generated.

Data Types: char | string

Description of the fault, specified as a string scalar or character vector.

Data Types: char | string

Fault information directory, specified as a string scalar or a character vector. You can only specify this argument for the first fault added to a model. If you do not specify this argument, the function saves the fault information file in the current folder.

Example: simulink.fault.addFault("myModel/DC Motor/Armature winding",FaultInfoDir="C:\myFolder")

Data Types: char | string

Output Arguments

collapse all

Fault on the specified model element, returned as a Fault object.

Version History

Introduced in R2023b