How to display the Output of a Fuzzy System in linguistic terms such as 'Good' or 'Bad'
2 views (last 30 days)
Show older comments
I am trying to work on the fuzzy logic using the command. I want to have my output to be either good or bad.
I have 2 input variable consisting of high medium and low value. My o/p would be good and bad based on the rules.
I don't want my output to be in the numeric value but rather as good/ bad , I have used this approach
fis=addvar(fis,'output','Result',[-1 2]);
fis=addmf(fis,'output',1,'Good',[-1 0 1]);
fis=addmf(fis,'output',1,'Bad',[0 1 2]);
I tried to eval the 'Result' based on the rules using
output=evalfis([0.4321 0.02294],fis)
But I am getting an error like this
MF index for output 1 in rule 3 is out of bound.
Error using evalfismex
Exiting ...
Error in evalfis (line 83)
[output,IRR,ORR,ARR] = evalfismex(input, fis, numofpoints);
Error in trial (line 70)
output=evalfis([0.4321 0.02294],fis)
Can anybody explain me where I may be wrong.
0 Comments
Answers (1)
Sam Chak
on 25 Apr 2025
Hi @sotna ledua
Since your post lacks additional details about the fuzzy system, I will create a simple fuzzy system for explanatory purposes.
The output of a fuzzy system in the MATLAB Fuzzy Logic Toolbox is always a crisp numeric value. If you wish to display the output of a fuzzy system in linguistic terms, such as 'Good' or 'Bad', you can use the dictionary() function to create associations between the numeric data and the linguistic terms. After that, you can use the lookup() function to find the association.
%% My Personal Fuzzy Assistant
fis = mamfis;
% Fuzzy Input 1
fis = addInput(fis, [0, 1.0], 'Name', 'Blood-Glucose');
fis = addMF(fis, 'Blood-Glucose', 'linzmf', [0.2, 0.8], 'Name', 'Low');
fis = addMF(fis, 'Blood-Glucose', 'linsmf', [0.2, 0.8], 'Name', 'High');
% Fuzzy Input 2
fis = addInput(fis, [0, 0.1], 'Name', 'Blood-Pressure');
fis = addMF(fis, 'Blood-Pressure', 'linzmf', [0.02, 0.08], 'Name', 'Low');
fis = addMF(fis, 'Blood-Pressure', 'linsmf', [0.02, 0.08], 'Name', 'High');
% Fuzzy Output
fis = addOutput(fis, [-1, 2], 'Name', 'Result');
fis = addMF(fis, 'Result', 'trimf', [-1 0 1], 'Name', 'Good');
fis = addMF(fis, 'Result', 'trimf', [ 0 1 2], 'Name', 'Bad');
% Fuzzy Rule
rules = ["If Blood-Glucose is Low and Blood-Pressure is Low then Result is Good"
"If Blood-Glucose is High and Blood-Pressure is High then Result is Bad"
];
fis = addRule(fis, rules);
%% My Medical Dictionary
Score = [ -1 0.5 2 ];
Health = ["Good" "Borderline Bad" "Bad"];
myDict = dictionary(Score, Health);
%% Health Screening Result
normalized_Blood_Glucose__reading = rand;
normalized_Blood_Pressure_reading = 0.1*rand;
output = evalfis(fis, [normalized_Blood_Glucose__reading, normalized_Blood_Pressure_reading]);
if output < 0.5
output = -1;
elseif output > 0.5
output = 2;
end
Result = lookup(myDict, output)
%% Plot fuzzy system
figure
subplot(211)
plotmf(fis, 'input', 1), grid on
subplot(212)
plotmf(fis, 'input', 2), grid on
sgtitle('Membership functions of Inputs')
figure
plotmf(fis, 'output', 1), grid on
title('Membership functions of Output')
figure
plotrule(fis)
0 Comments
See Also
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!

