Error using FuzzyInfer​enceSystem​/addOutput (line 866) Upper range value for variable must be greater than lower range value. Error in rulepruning (line 24) fis = addOutput(fi

% Create a sample FIS
% fis = mamfis('tipper');
% fis = mamfis("NumInputs",3,"NumOutputs",1)
fis = mamfis('Name',"tipper");
fis = addInput(fis,'NumMFs',3,'MFType',"gaussmf");
fis.Inputs(1).Name = "service";
fis.Inputs(1).Range = [0 10];
% fis = addInput(fis, 'service', [0 10]);
% fis = addInput(fis, 'food', [0 10]);
% fis = addOutput(fis, 'tip', [0 30]);
fis.Inputs(2).Name = "food";
fis.Inputs(2).Range = [0 10];
fis.Outputs(1).Name = "tip";
fis.Outputs(1).Range = [0 30];
% Add output membership functions
% Add output membership functions
out_mf1 = zmf(fis.Outputs(1).Range, [0 15]); % 'low'
fis = addOutput(fis, out_mf1, 'Name', 'low');
Error using FuzzyInferenceSystem/addOutput (line 866)
Upper range value for variable must be greater than lower range value.
out_mf2 = zmf(fis.Outputs(1).Range, [10 20]); % 'medium'
fis = addOutput(fis, out_mf2, 'Name', 'medium');
out_mf3 = zmf(fis.Outputs(1).Range, [15 25]); % 'high'
fis = addOutput(fis, out_mf3, 'Name', 'high');
out_mf4 = zmf(fis.Outputs(1).Range, [20 30]); % 'very_high'
fis = addOutput(fis, out_mf4, 'Name', 'very_high');
% Add rules
rules = [...
"If service is poor and food is rancid, then tip is cheap"; ...
"If service is good and food is delicious, then tip is generous"; ...
"If service is excellent and food is amazing, then tip is very generous"; ...
"If service is poor and food is delicious, then tip is average"; ...
"If service is good and food is rancid, then tip is little"; ...
];
fis = addRule(fis, rules);
% Perform rule pruning
[pruned_fis, pruned_rules, pruned_outputs] = pruneRules(fis, 0.2);
% Get remaining rules
remaining_rules = getRuleValues(pruned_fis);

 Accepted Answer

The syntax to add output membership functions is incorrect. Use 'addMF()' instead. However, it is highly recommended to use the Fuzzy Logic Designer app with interactive user interface.
% Create a sample FIS
fis = mamfis('Name',"tipper");
fis = addInput(fis,'NumMFs',3,'MFType',"gaussmf");
% Create Fuzzy Input #1
fis.Inputs(1).Name = "service";
fis.Inputs(1).Range = [0 10];
% Create Fuzzy Input #2
fis.Inputs(2).Name = "food";
fis.Inputs(2).Range = [0 10];
% Create Fuzzy Output #1
fis.Outputs(1).Name = "tip";
fis.Outputs(1).Range = [0 30];
% Add output membership functions
fis = addMF(fis, 'tip', 'zmf', [ 0 15], 'Name', 'low');
fis = addMF(fis, 'tip', 'zmf', [10 20], 'Name', 'medium');
fis = addMF(fis, 'tip', 'zmf', [15 25], 'Name', 'high');
fis = addMF(fis, 'tip', 'zmf', [20 30], 'Name', 'very_high');
plotmf(fis, 'output', 1), grid on, title('Tip')
% % Add rules
% rules = [...
% "If service is poor and food is rancid, then tip is cheap"; ...
% "If service is good and food is delicious, then tip is generous"; ...
% "If service is excellent and food is amazing, then tip is very generous"; ...
% "If service is poor and food is delicious, then tip is average"; ...
% "If service is good and food is rancid, then tip is little"; ...
% ];
% fis = addRule(fis, rules);
%
% % Perform rule pruning
% [pruned_fis, pruned_rules, pruned_outputs] = pruneRules(fis, 0.2);
%
% % Get remaining rules
% remaining_rules = getRuleValues(pruned_fis);

8 Comments

Thank you for your prompt response. It ran but when i added the add rule section, it gave another error :
"Error using FuzzyInferenceSystem/addRule (line 1153)
Index exceeds the number of array elements. Index must not exceed 4.
Error in rulepruning (line 39)
fis = addRule(fis, rules);"
How can I fix this
Please show the rule code to carry out further investigation.
If the proposed 'addMF()' solution has eliminated the error message, I would encourage you to consider clicking 'Accept' ✔ on the answer and voting 👍 for it. Your support would be greatly appreciated.
If you have encountered a new issue with the fuzzy logic design, you are welcome to post a new question, and I would be happy to assist you further.
You're welcome, @Michael Bamidele. Are you designing a decision-making system based on the concept of pure human reasoning (no math involved) using Fuzzy Logic just like the Tipper example?
I neglected to mention that both the pruneRules() and getRuleValues() functions are not built-in MATLAB functions. As a result, I am unable to test them. Are these functions available from the MATLAB File Exchange?
help pruneRules
pruneRules not found. Search the documentation for pruneRules docsearch pruneRules
help getRuleValues
getRuleValues not found. Search the documentation for getRuleValues docsearch getRuleValues

Sign in to comment.

More Answers (0)

Categories

Find more on Fuzzy Logic Toolbox 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!