%% Remove Membership Function from Fuzzy Inference System
% Create a Mamdani fuzzy inference system with two inputs and one output. By default, when you specify the number of inputs and outputs, mamfis adds three membership functions to each variable.

fis = mamfis('NumInputs',3,'NumOutputs',1)

% Name the variables. For this example, give the second input variable and the output variable the same name.

fis.Inputs(1).Name = "speed";
fis.Inputs(2).Name = "throttle";
fis.Inputs(3).Name = "distance";
fis.Outputs(1).Name = "throttle";

% View the membership functions for the first input variable.

plotmf(fis,"input",1)

% Remove the second membership function, mf2, from the first input variable.

fis = removeMF(fis,"speed","mf2");

% View the membership functions again. The specified membership function has been removed.

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 removing a membership function. For example, remove the mf3 membership function from the output variable.

fis = removeMF(fis,"throttle","mf3",'VariableType',"output");

% View the membership functions of the output variable.

plotmf(fis,"output",1)

% Copyright 2018 The MathWorks, Inc.