%% 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)

% Copyright 2019 The MathWorks, Inc.