addMF
Add membership function to fuzzy variable
Syntax
Description
adds a membership function with the specified type and parameters.fisOut
= addMF(fisIn
,varName
,type
,parameters
)
configures the membership function using one or more name-value pair arguments.fisOut
= addMF(___,Name,Value
)
adds a default membership function to fuzzy variable varOut
= addMF(varIn
)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
.
adds a membership function with the specified type and parameters.varOut
= addMF(varIn
,type
,parameters
)
specifies the name of the membership function using the varOut
= addMF(___,Name,Value
)Name
name-value 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 argument.
Examples
Add Membership Function to Fuzzy Inference System
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)
Add Membership Function to Type-2 Fuzzy Inference System
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)
Add Membership Function to Fuzzy Variable
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];
Add Type-2 Membership Function to Fuzzy Variable
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
Specify Custom Membership Functions at Command Line
To use a custom membership function when designing a FIS at the MATLAB® command line, specify the name and parameters when adding the membership function using addMF
. For example, the following command adds custom membership function custmf1
to the first input variable, input1
, of FIS myFIS
and names it customMF1
.
Create a FIS and add an input variable.
myFIS = mamfis; myFIS = addInput(myFIS);
Add custom membership function custmf1
to the first input variable, input1
, of this FIS and name it customMF1
.
myFIS = addMF(myFIS,"input1","custmf1",[0 1 2 4 6 8 9 10],... "Name","customMF1");
Ensure that the range of the input variable matches the expected range of your membership function. For this example, set the range of the first input to [0 10]
.
myFIS.Inputs(1).Range = [0 10];
To verify the appearance of your membership function, you can plot it using plotMF
.
plotmf(myFIS,"input",1)
Input Arguments
fisIn
— Fuzzy inference system
mamfis
object | sugfis
object | mamfistype2
object | sugfistype2
object
Fuzzy inference system, specified as one of the following:
mamfis
object — Mamdani fuzzy inference systemsugfis
object — Sugeno fuzzy inference systemmamfistype2
object — Type-2 Mamdani fuzzy inference systemsugfistype2
object — Type-2 Sugeno fuzzy inference system
varName
— Variable name
string | character vector
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.
type
— Membership function type
"trimf"
(default) | string | character vector | function handle
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 Type | Description | For More Information |
---|---|---|
"gbellmf" | Generalized bell-shaped membership function | gbellmf |
"gaussmf" | Gaussian membership function | gaussmf |
"gauss2mf" | Gaussian combination membership function | gauss2mf |
"trimf" | Triangular membership function | trimf |
"trapmf" | Trapezoidal membership function | trapmf |
"linsmf" | Linear s-shaped saturation membership function (since R2022a) | linsmf |
"linzmf" | Linear z-shaped saturation membership function (since R2022a) | linzmf |
"sigmf" | Sigmoidal membership function | sigmf |
"dsigmf" | Difference between two sigmoidal membership functions | dsigmf |
"psigmf" | Product of two sigmoidal membership functions | psigmf |
"zmf" | Z-shaped membership function | zmf |
"pimf" | Pi-shaped membership function | pimf |
"smf" | S-shaped membership function | smf |
"constant" | Constant membership function for Sugeno output membership functions | Sugeno Fuzzy Inference Systems |
"linear" | Linear membership function for Sugeno output membership functions | |
String or character vector | Name of a custom membership function in the current working folder or on the MATLAB path. Custom output membership functions are not supported for Sugeno systems. | Build Fuzzy Systems Using Custom Functions |
Function handle | Handle to a custom membership function in the current working folder or on the MATLAB path. Custom output membership functions are not supported for Sugeno systems. |
parameters
— Membership function parameters
[0 0.5 1]
(default) | vector
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.
varIn
— Fuzzy variable
fisvar
object
Fuzzy variable, specified as a fisvar
object.
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: fis = addMF(fis,"distance",Name="high")
Before R2021a, use commas to separate each name and value, and enclose
Name
in quotes.
Example: fis = addMF(fis,"distance","Name","high")
Name
— Membership function name
string | character vector
Membership function name, specified as 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.
VariableType
— Variable type
"input"
| "output"
Variable type, specified as 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.
LowerScale
— Lower membership function scaling factor
1
(default) | positive scalar less than or equal to 1
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.
LowerLag
— Lower membership function delay factor
[0.2 0.2]
(default) | scalar value between 0
and 1
| vector of length 2
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
andgbellmf
One-sided MFs —
sigmf
,smf
, andzmf
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
fisOut
— Fuzzy inference system
mamfis
object | sugfis
object | mamfistype2
object | sugfistype2
object
Fuzzy inference system, specified as one of the following:
mamfis
object — Mamdani fuzzy inference systemsugfis
object — Sugeno fuzzy inference systemmamfistype2
object — Type-2 Mamdani fuzzy inference systemsugfistype2
object — Type-2 Sugeno fuzzy inference system
fisOut
contains the added membership function, with all other
properties matching the properties of
fisIn
fisOut
contains the added membership
function, with all other properties matching the properties of
fisIn
varOut
— Fuzzy variable
fisvar
object
Fuzzy variable, returned as a fisvar
object.
varOut
contains the added membership function, with all other
properties matching the properties of varIn
.
Version History
Introduced in R2018bR2024b: Fuzzy inference system structures not supported
addMF
no longer supports fuzzy inference system structures.
Use mamfis
and sugfis
objects
instead. To convert existing fuzzy inference system structures to objects, use the convertfis
function.
R2019b: Fuzzy inference system structures will not be supported
Support for fuzzy inference systems structures will be removed in a future release. This
change was announced in R2018b. Using fuzzy inference system structures with
addMF
issues a warning starting in R2019b.
R2018b: Function renamed and method for specifying variable and membership function changed
The name and behavior of the addmf
function has changed. Now:
addmf
isaddMF
You specify the variable to which you want to add the membership function by name rather than by index.
You specify the name of the membership function using a name-value pair argument.
This table shows some typical usages of addmf
for adding membership
functions to fuzzy variables and how to update your code. In this table,
fis
is a fuzzy inference system with two inputs,
service
and food
, and one output,
tip
.
If your code has this form: | Use this code instead: |
---|---|
fis = addmf(fis'input',1,... 'poor',... 'gaussmf',[1.5 0]) |
fis = addMF(fis,"service",... "gaussmf",[1.5 0], 'Name',"poor") |
fis = addmf(fis,'input',2,... 'rancid',... 'trapmf',[-2 0 1 3]) |
fis = addMF(fis,"food",... "trapmf",[-2 0 1 3],... 'Name',"rancid") |
fis = addmf(fis,'output',1,... 'cheap',... 'trimf',[0 5 10]) |
fis = addMF(fis,"tip",... "trimf",[0 5 10],... 'Name',"cheap") |
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)