addMF

Add membership function to fuzzy variable

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.

If varIn does not contain any membership functions, this syntax adds a default type-1 membership function. Otherwise, the type of the added membership function matches the type of the existing membership functions in varIn.

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.

To add a type-2 membership function to a fuzzy variable with no existing membership functions, you must specify either the LowerLag or LowerScale 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 type-2 Sugeno fuzzy system, and add two input variables and one output variable.

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

Add a membership function to the first input variable, specifying a trapezoidal membership function, and set the membership function parameters. This type-2 membership function uses default lower membership function lag and scale parameters.

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

You can also specify the configuration of the lower MF when adding a type-2 membership function.

fis = addMF(fis,"speed","trapmf",[10 30 50 70],'LowerScale',0.8,'LowerLag',0.1);

You can also specify the name of your membership function 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)

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:

    Type
    Parameters
    Name

  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];

Create a fuzzy variable with a specified range. By default, this variable has no membership functions.

var = fisvar([0 9]);

To add a type-2 membership function to a variable with no existing membership functions, specify either a LowerLag or LowerScale value for the membership function. For example specify a lower scale value.

var = addMF(var,"trimf",[0 3 6],'LowerScale',1);

Once a variable contains a type-2 membership function, you can add additional type-2 membership functions without specifying one of these parameters.

var = addMF(var,"trimf",[3 6 9]);

View the membership functions.

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

    Type
    UpperParameters
    LowerScale
    LowerLag
    Name

  Details:
         Name      Type      Upper Parameters    Lower Scale    Lower Lag 
         _____    _______    ________________    ___________    __________

    1    "mf1"    "trimf"      0    3    6            1         0.2    0.2
    2    "mf2"    "trimf"      3    6    9            1         0.2    0.2

Input Arguments

collapse all

Fuzzy inference system, specified as one of the following:

  • mamfis object — Mamdani fuzzy inference system

  • sugfis object — Sugeno fuzzy inference system

  • mamfistype2 object — Type-2 Mamdani fuzzy inference system

  • sugfistype2 object — Type-2 Sugeno fuzzy inference system

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)Sugeno Fuzzy Inference Systems
"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.

When fisIn is a type-1 FIS or varIn contains type-1 membership functions, parameters sets the Parameters property of the added membership function.

When fisIn is a type-2 FIS or varIn contains type-2 membership functions, parameters sets the UpperParameters property of the added membership function.

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 does not apply when adding when adding a membership function to a fisvar object.

Lower membership function scaling factor for type-2 membership functions, specified as a positive scalar less than or equal to 1. Use LowerScale to define the maximum value of the lower membership function.

Depending on the value of LowerLag, the actual maximum lower membership function value can be less than LowerScale.

This name-value pair applies only when adding type-2 membership functions.

Lower membership function delay factor for type-2 membership functions, specified as a scalar value or a vector of length two. You can specify lag values between 0 and 1, inclusive.

This name-value pair applies only when adding type-2 membership functions.

The following membership function types support only a scalar LowerLag value:

  • Symmetric MFs — gaussmf and gbellmf

  • One-sided MFs — sigmf, smf, and zmf

All other built-in membership functions support either a scalar or vector LowerLag value. For these membership functions, when you specify a:

  • Scalar value, the same lag value is used for both the left and right side of the membership function.

  • Vector value, you can define different lag values for the left and right sides of the membership function.

The lag value defines the point at which the lower membership function value starts increasing from zero based on the value of the upper membership function. For example, a lag value of 0.1 indicates that the lower membership function becomes positive when the upper membership function has a membership value of 0.1.

When the lag value is zero, the lower membership function starts increasing at the same point as the upper membership function.

Some membership function types restrict the maximum lag value. For example, LowerLag must be less than 1 for the gaussmf, gauss2mf, gbellmf, sigmf, dsigmf, and psigmf membership functions.

Output Arguments

collapse all

Fuzzy inference system, specified as one of the following:

  • mamfis object — Mamdani fuzzy inference system

  • sugfis object — Sugeno fuzzy inference system

  • mamfistype2 object — Type-2 Mamdani fuzzy inference system

  • sugfistype2 object — Type-2 Sugeno fuzzy inference system

fisOut contains the added membership function, with all other properties matching the properties of fisInfisOut 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

Warns starting in R2019b

Introduced in R2018b