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 the sldemo_fuelsys_fault_analyzer model in the Define Fault Behaviors example.

openExample('faultanalyzer/DefineFaultBehaviorsExample')
model = "sldemo_fuelsys_fault_analyzer";
open_system(model)

Add a fault to each input port of the To Controller subsystem.

Simulink.fault.addFault(...
model + "/To Controller/Inport/1");
Simulink.fault.addFault(...
model + "/To Controller/Inport/2");
Simulink.fault.addFault(...
model + "/To Controller/Inport/3");
Simulink.fault.addFault(...
model + "/To Controller/Inport/4");

Open the fault_analyzer_intro model.

openExample('faultanalyzer/FaultAnalyzerIntroExample')

Add a fault named myFault to the output port of the Sine Wave block.

Simulink.fault.addFault("fault_analyzer_intro/Sine Wave/Outport/1",...
Name="myFault");

Input Arguments

collapse all

Path or handle of model element, specified as a string scalar, character vector, or handle. In Simulink® models, this argument must be the path or handle of a block output or input port. In Simscape™ blocks, this argument must be the path of a fault-capable model subelement. In System Composer™ models, this argument must be the path of a component output or input port.

Example: "myModel/Sine Wave/Outport/1"

Data Types: string | char | double

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. For more information, see Add Faults to the Model.

Example: simulink.fault.addFault("myModel/Sine Wave/Outport/1",FaultInfoDir="C:\myFolder")

Data Types: char | string

Output Arguments

collapse all

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

Tips

  • To add behavior to a fault, use the addBehavior function.

  • To specify the trigger type, use dot notation and specify the TriggerType property.

Version History

Introduced in R2023b