Main Content

addBehavior

Add signal behavior to fault

Since R2023b

Description

addBehavior(fault,faultModel) adds fault behavior to the fault, fault, and stores the fault behavior parameters in the fault model, faultModel.

example

addBehavior(fault,faultModel,Name=Value) adds the fault behavior to the fault using one or more name-value arguments.

example

Examples

collapse all

Open the fault_analyzer_intro model.

openExample('faultanalyzer/FaultAnalyzerIntroExample')

Add a fault to the Sine Wave block.

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

Assign empty behavior to the fault and store the behavior in a fault model named myBehaviorModel on the path.

addBehavior(fault,"myBehaviorModel");

Open the fault_analyzer_intro model.

openExample('faultanalyzer/FaultAnalyzerIntroExample')

Add a fault to the Sine Wave block output port.

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

Assign noise behavior available in the mwfaultlib library to the fault and store the behavior in a fault model named myBehaviorModel on the path.

addBehavior(myFault,"myBehaviorModel",...
FaultBehavior="mwfaultlib/Add Noise");

Input Arguments

collapse all

Fault, specified as a Fault object.

File name of the fault model, specified as a string scalar or character vector. The function creates a Fault Subsystem block that models the behavior in this fault model.

For more information on this block and this model, see Investigate the Fault Behavior and Create Predefined and Custom Fault Behaviors.

Data Types: char | string

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: addBehavior(fault,"myBehaviorModel",FaultBehavior="mwfaultlib/Gain") adds gain behavior to the fault, fault, in the fault model, myBehaviorModel.

Example: addBehavior(fault,"myBehaviorModel",FaultModelDir="C:\myFiles") adds behavior to the fault, fault, in the fault model, myBehaviorModel, and stores the fault model in the C:\myFiles folder.

Directory of the fault model, specified as a string scalar or character vector. If you enter an empty string or character vector, the function uses the current directory. The directory must exist before you specify it.

Data Types: char | string

Fault behavior, specified as one of these values:

ValueDescription
"mwfaultlib/Absolute Value"Sets the signal value to its absolute value when the fault triggers.
"mwfaultlib/Add Noise"Adds noise to the signal when the fault triggers.
"mwfaultlib/Gain"Adds a gain to the signal when the fault triggers.
"mwfaultlib/Negate Value"Multiplies the signal by -1 when the fault triggers.
"mwfaultlib/Offset-by-1"Subtracts -1 from the signal when the fault triggers.
"mwfaultlib/Stuck-at-Constant"Sets the signal to a constant value when the fault triggers. The default value is 1.
"mwfaultlib/Stuck-at-Ground"Sets the signal to zero when the fault triggers.
"mwfaultlib/Unit Delay"Applies a unit delay to the signal when the fault triggers.
string scalar or character vectorSpecify a custom fault behavior in a custom library.

Simscape™ blocks do not support this name-value argument.

If you do not specify this argument, the function assigns a Fault Subsystem block that contains only a Fault Inport and Fault Outport block. You must add and connect blocks in the Fault Subsystem block before simulating.

To see the fault behaviors you can add, use Simulink.fault.libraryBlocks. You can specify additional fault behaviors by registering a custom library. When specifying a behavior from a registered custom library, specify the library name followed a slash and then the behavior name. For example, if you have a custom library named myLib that contains a behavior named myBehavior, specify this argument as "myLib/myBehavior".

For more information on creating and registering custom fault behavior libraries, see Create Predefined and Custom Fault Behaviors.

Data Types: char | string

Limitations

After you add behavior to a fault, you cannot add additional behavior to the fault. If you assigned incorrect behavior to the fault, delete the old behavior with the deleteBehavior function, then add new behavior to the fault.

Version History

Introduced in R2023b