How to input a NaN (as a nonexistent input variable) when evaluating a fuzzy system using evalfis
15 views (last 30 days)
Show older comments
Hi all
I have designed a fuzzy logic model using the fuzzy logic toolbox.
The model has four input variables [x1, x2, x3, x4], and the variable x3 does not exist when x1<10. The rules have been designed to take this into account.
In the app, I can generate a surface for [NaN, 0, 0, NaN], which will plot the output as a function of x1 and x4 when x2 = 0 and x3 = 0. I can also create a surface for [NaN, 0, NaN, NaN] in which it is assumed x3 is absent. These surfaces look ok.
Now, I want to evaluate my model from the command line with evalfis
output = evalfis(myfuzzy, [x1 x2 x3 x4])
I have no idea how to input that the variable x3 is absent. I have tried
output = evalfis(myfuzzy, [x1 x2 nan x4])
but I get an error, any idea how to do this?
8 Comments
Answers (1)
Sam Chak
on 21 Apr 2025
Hi @NaN
I am revisiting the problem after more than a year and believe that two fuzzy systems (fis11 and fis12) should be created separately, mimicking the concept of a piecewise linear function. The fuzzy system fis11 takes four inputs {x1, x2, x3, x4} and returns a non-zero output when x1 < 10. If x1 ≥ 10, fis11 returns 0. The fuzzy system fis12 takes three inputs {x1, x2, x4} and returns a non-zero output when x1 ≥ 10. If x1 < 10, fis12 returns 0. The fuzzy system fis1 functions as an additive operation but actually returns either the output of fis11 or the output of fis12.
%% fis11 works when x1 < 10 and x3 is defined
% When x1 >= 10, fis1 should output 0
fis11 = mamfis('Name', 'fis11', 'NumInputs', 4, 'NumOutputs', 1);
fis11.Inputs(1).Name = "x1";
fis11.Inputs(2).Name = "x2";
fis11.Inputs(3).Name = "x3";
fis11.Inputs(4).Name = "x4";
fis11.Outputs(1).Name = "y1";
%% fis12 works when x1 >= 10 and x3 is undefined
% When x1 < 10, fis2 should output 0
fis12 = mamfis('Name', 'fis12', 'NumInputs', 3, 'NumOutputs', 1);
fis12.Inputs(1).Name = "x1";
fis12.Inputs(2).Name = "x2";
fis12.Inputs(3).Name = "x4";
fis12.Outputs(1).Name = "y2";
%% fis1 decides on either output of fis11 or output of fis12
fis1 = mamfis('Name', 'fis1', 'NumInputs', 2, 'NumOutputs', 1);
fis1.Inputs(1).Name = "y1";
fis1.Inputs(2).Name = "y2";
fis1.Outputs(1).Name = "y3";
%% fis2 is the 2nd stage computation that takes the output of fis1
fis2 = mamfis('Name', 'fis2', 'NumInputs', 3, 'NumOutputs', 1);
fis2.Inputs(1).Name = "x3";
fis2.Inputs(2).Name = "y3";
fis2.Inputs(3).Name = "x5";
fis2.Outputs(1).Name = "y4";
%% connections
con1 = ["fis11/x1", "fis12/x1"];
con2 = ["fis11/x2", "fis12/x2"];
con3 = ["fis11/x4", "fis12/x4"];
con4 = ["fis11/y1", "fis1/y1"];
con5 = ["fis12/y2", "fis1/y2"];
con6 = ["fis11/x3", "fis2/x3"];
con7 = ["fis1/y3", "fis2/y3"];
%% create a FIS Tree
tree = fistree([fis11 fis12 fis1 fis2], [con1; con2; con3; con4; con5; con6; con7]);
plotfis(tree)
0 Comments
See Also
Categories
Find more on Fuzzy Logic in Simulink in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


