fis1 = mamfis('Name',"tipper1");
fis1 = addInput(fis1,[0 10],'Name',"service");
fis1 = addMF(fis1,"service","gaussmf",[1.5 0],'Name',"poor");
fis1 = addMF(fis1,"service","gaussmf",[1.5 5],'Name',"good");
fis1 = addMF(fis1,"service","gaussmf",[1.5 10],'Name',"excellent");
fis1 = addInput(fis1,[0 10],'Name',"food");
fis1 = addMF(fis1,"food","trapmf",[-2 0 1 3],'Name',"rancid");
fis1 = addMF(fis1,"food","trapmf",[7 9 10 12],'Name',"delicious");
fis1 = addOutput(fis1,[0 30],'Name',"tip1");
fis1 = addMF(fis1,"tip1","trimf",[0 5 10],'Name',"cheap");
fis1 = addMF(fis1,"tip1","trimf",[10 15 20],'Name',"average");
fis1 = addMF(fis1,"tip1","trimf",[20 25 30],'Name',"generous");
rulefis1a = "service==poor | food==rancid => tip1=cheap";
rulefis1b = "service==good => tip1=average";
rulefis1c = "service==excellent | food==delicious => tip1=generous";
rulefis1d = [rulefis1a rulefis1b rulefis1c];
fis1b = addRule(fis1,rulefis1d);
fis2 = mamfis('Name',"tipper2");
fis2 = addInput(fis2,[0 10],'Name',"service");
fis2 = addMF(fis2,"service","gaussmf",[1.5 0],'Name',"poor");
fis2 = addMF(fis2,"service","gaussmf",[1.5 5],'Name',"good");
fis2 = addMF(fis2,"service","gaussmf",[1.5 10],'Name',"excellent");
fis2 = addInput(fis2,[0 10],'Name',"food");
fis2 = addMF(fis2,"food","trapmf",[-2 0 1 3],'Name',"rancid");
fis2 = addMF(fis2,"food","trapmf",[7 9 10 12],'Name',"delicious");
fis2 = addOutput(fis2,[0 30],'Name',"tip2");
fis2 = addMF(fis2,"tip2","trimf",[0 5 10],'Name',"cheap");
fis2 = addMF(fis2,"tip2","trimf",[10 15 20],'Name',"average");
fis2 = addMF(fis2,"tip2","trimf",[20 25 30],'Name',"generous");
rulefis2a = "service==poor | food==rancid => tip2=cheap";
rulefis2b = "service==good => tip2=average";
rulefis2c = "service==excellent | food==delicious => tip2=generous";
rulefis2d = [rulefis2a rulefis2b rulefis2c];
fis2b = addRule(fis2,rulefis2d);
fis3 = mamfis('Name','fis3');
fis3 = addInput(fis3,[0 30],'Name',"tip1");
fis3 = addMF(fis3,"tip1","trimf",[0 5 10],'Name',"cheap");
fis3 = addMF(fis3,"tip1","trimf",[10 15 20],'Name',"average");
fis3 = addMF(fis3,"tip1","trimf",[20 25 30],'Name',"generous");
fis3 = addInput(fis3,[0 30],'Name',"tip2");
fis3 = addMF(fis3,"tip2","trimf",[0 5 10],'Name',"cheap");
fis3 = addMF(fis3,"tip2","trimf",[10 15 20],'Name',"average");
fis3 = addMF(fis3,"tip2","trimf",[20 25 30],'Name',"generous");
fis3.Outputs(1).Name = "final_tip";
fis3 = addMF(fis3,"final_tip","trapmf",[-2 0 1 3],'Name',"low");
fis3 = addMF(fis3,"final_tip","trapmf",[7 9 10 12],'Name',"high");
rulefis3a = "tip1==cheap | tip2==average => final_tip=low";
rulefis3b = "tip1==average => final_tip=low";
rulefis3c = "tip1==generous | tip2==generous => final_tip=high";
rulefis3d = [rulefis3a rulefis3b rulefis3c];
fis3b = addRule(fis3,rulefis3d);
con1 = ["tipper1/tip1" "fis3/tip1"];
con2 = ["tipper2/tip2" "fis3/tip2"];
aggTree = fistree([fis1b fis2b fis3],[con1;con2]);
aggTree.FIS(3) = addRule(aggTree.FIS(3), rulefis3d)
output = evalfis(aggTree,[0.2 0.25 0.3 0.2])
Best Answer