addMF

Add membership function to fuzzy variable

Syntax

fisOut = addMF(fisIn,varName)
fisOut = addMF(fisIn,varName,type,parameters)
fisOut = addMF(___,Name,Value)
varOut = addMF(varIn)
varOut = addMF(varIn,type,parameters)
varOut = addMF(___,Name,Value)

Description

example

fisOut = addMF(fisIn,varName) adds a default membership function to the input or output variable varName in the fuzzy inference system fisIn and returns the resulting fuzzy system in fisOut.

example

fisOut = addMF(fisIn,varName,type,parameters) adds a membership function with the specified type and parameters.

example

fisOut = addMF(___,Name,Value) configures the membership function using one or more name-value pair arguments.

example

varOut = addMF(varIn) adds a default membership function to fuzzy variable varIn and returns the resulting fuzzy variable in varOut.

example

varOut = addMF(varIn,type,parameters) adds a membership function with the specified type and parameters.

example

varOut = addMF(___,Name,Value) specifies the name of the membership function using the Name name-value pair argument.

Examples

collapse all

Create a Mamdani fuzzy system, and add three input variables and one output variable. For this example, give the second input variable and the output variable the same name.

fis = mamfis;
fis = addInput(fis,[0 80],"Name","speed");
fis = addInput(fis,[0 100],"Name","throttle");
fis = addInput(fis,[0 10],"Name","distance");
fis = addOutput(fis,[0 100],"Name","throttle");

Add a membership function to the first input variable, specifying a trapezoidal membership function, and set the membership function parameters.

fis = addMF(fis,"speed","trapmf",[-5 0 10 30]);

You can also specify the name of your membership when you add it to a fuzzy system. Add a membership function called "high" to the first input variable.

fis = addMF(fis,"speed","trapmf",[50 70 80 85],'Name',"high");

View the membership functions for the first input variable.

plotmf(fis,"input",1)

If your system has an input variable with the same name as an output variable, you must specify the variable type when adding a membership function. For example, add a membership function to the output variable.

fis = addMF(fis,"throttle","trimf",[0 20 40],'VariableType',"output");
plotmf(fis,"output",1)

Alternatively, you can add a default membership function to a fuzzy system and set its parameters using dot notation. For example, add and configure a membership function for the third input variable.

fis = addMF(fis,"distance");
fis.Inputs(3).MembershipFunctions(1).Type = "trapmf";
fis.Inputs(3).MembershipFunctions(1).Parameters = [-1 0 2 4];
plotmf(fis,"input",3)

Create a fuzzy variable with a specified range.

var = fisvar([0 1]);

Add a membership function to the variable, specifying a trapezoidal membership function, and set the membership function parameters.

var = addMF(var,"trapmf",[-0.5 0 0.2 0.4]);

You can also specify the name of your membership when you add it to a fuzzy variable. For example, add a membership function called "large".

var = addMF(var,"trapmf",[0.6 0.8 1 1.5],'Name',"large");

View the membership functions.

var.MembershipFunctions
ans = 
  1x2 fismf array with properties:

    Name
    Type
    Parameters

  Details:
          Name        Type               Parameters         
         _______    ________    ____________________________

    1    "mf1"      "trapmf"    -0.5       0     0.2     0.4
    2    "large"    "trapmf"     0.6     0.8       1     1.5

Alternatively, you can add a default membership function to a fuzzy variable and set its parameters using dot notation.

var = fisvar([0 1]);
var = addMF(var);
var.MembershipFunctions(1).Type = "trapmf";
var.MembershipFunctions(1).Parameters = [-0.5 0 0.2 0.4];

Input Arguments

collapse all

Fuzzy inference system, specified as a mamfis or sugfis object.

Variable name, specified as a string or character vector. You can specify the name of either an input or output variable in your FIS. If your system has an input variable with the same name as an output variable, specify the type of the variable you want to add a membership function to using the VariableType name-value pair.

Membership function type, specified as a string or character vector that contains the name of a function in the current working folder or on the MATLAB® path. You can also specify a handle to such a function. When you specify type, you must also specify parameters.

This table describes the values that you can specify for type.

Membership Function TypeDescriptionFor More Information
"gbellmf"Generalized bell-shaped membership functiongbellmf
"gaussmf"Gaussian membership functiongaussmf
"gauss2mf"Gaussian combination membership functiongauss2mf
"trimf"Triangular membership functiontrimf
"trapmf"Trapezoidal membership functiontrapmf
"sigmf"Sigmoidal membership functionsigmf
"dsigmf"Difference between two sigmoidal membership functionsdsigmf
"psigmf"Product of two sigmoidal membership functionspsigmf
"zmf"Z-shaped membership functionzmf
"pimf"Pi-shaped membership functionpimf
"smf"S-shaped membership functionsmf
"constant"Constant membership function (not supported for output variables of Mamdani systems or for any input variables)What Is Sugeno-Type Fuzzy Inference?
"linear"Linear membership function (not supported for output variables of Mamdani systems or for any input variables)
String or character vectorName of a custom membership function in the current working folder or on the MATLAB path. Custom functions are not supported for output variables of Sugeno systems.Build Fuzzy Systems Using Custom Functions
Function handleHandle to a custom membership function in the current working folder or on the MATLAB path. Custom functions are not supported for output variables of Sugeno systems.

Membership function parameters, specified as a vector. The length of the parameter vector depends on the membership function type. When you specify parameters, you must also specify type.

Fuzzy variable, specified as a fisvar object.

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: 'Name',"large" specifies the membership function name "large"

Membership function name, specified as the comma-separated pair consisting of 'Name' and a string or character vector. The default membership function name is "mf<uniqueIndex>", where uniqueIndex is automatically generated based on the current number of membership functions in the associated variable.

Variable type, specified as the comma-separated pair 'VariableType' and one of the following:

  • "input" — Input variable

  • "output" — Output variable

If your system has an input variable with the same name as an output variable, specify which variable to add the membership function to VariableType.

This name-value pair applies only when adding a membership function to a mamfis or sugfis object.

Output Arguments

collapse all

Fuzzy inference system, returned as a mamfis or sugfis object. fisOut contains the added membership function, with all other properties matching the properties of fisIn.

Fuzzy variable, returned as a fisvar object. varOut contains the added membership function, with all other properties matching the properties of varIn.

Compatibility Considerations

expand all

Behavior changed in R2018b

Not recommended starting in R2018b

Introduced in R2018b