How to know that each of the output is computed when the input is belong for specific range and print it in the same output?

7 views (last 30 days)
Hello everyone, I need a help in my code which I built it to use it in my Fuzzy Logic research paper.
The following is a function that I buit it up:
function MF1=evalMF1(x)
global L M H
MF1=[];
MF = @(x,z) max(min([(x-z(1))/(z(2)-z(1)), (z(3)-x)/(z(3)-(z(2)))]),0);
if(x>=L(1)&& x<=L(3))
MF1= [MF1 MF(x,L)] ;
end
if(x>=M(1)&& x<=M(3))
MF1= [MF1 MF(x,M)] ;
end
if(x>=H(1)&& x<=H(3))
MF1= [MF1 MF1(x,H)] ;
end
end
Now the following code I use it to recall the function:
% MF for input
global L M H;
L=[0 10 20] ;
M= [15 25 35] ;
H= [30 40 50] ;
In = evalMF1(16)
For example the output of the above In = evalMF1(16) is
In =
0.4000 0.1000
Now my question is the following:
How can I add to the output result of "In = evalMF1(16)" the range (In the other meaning it is the lingusitic varibale i.e L, M,H) that are each of the output belong to. For the above example the output that I need:
In =
L M
0.4000 0.1000
thats means 0.4 is computed when x belongs to L and 0.1is computed when x belongs to M
in this exapmle when x=16 , two of MF1 was computed, the first MF1 is computed when x belongs to L range, the second MF1 is computed when x belongs to M
If it is hard to use combinations of letters and numbers, we can donate to the L for exapmle L= 1 and so on... But it is better to be letters
I appreciate the any help. Thanks
  1 Comment
Rik
Rik on 23 Aug 2022
Global variables are very hard to debug and almost never needed to solve the problem. They often cause more problems than they solve.
This is essentially looking up a value from a lookup table.
What exactly is your question? How to add a line to your lookup table?

Sign in to comment.

Answers (1)

rumin diao
rumin diao on 23 Aug 2022
you could add a new variable in the function and use it to return 'L M H', i've added a variable 'Belong' and here's the code:
% MF for input
global L M H;
L=[0 10 20] ;
M= [15 25 35] ;
H= [30 40 50] ;
[Belong In] = evalMF1(16)
function [Belong MF1]=evalMF1(x)
global L M H
MF1=[];
Belong = [];
MF = @(x,z) max(min([(x-z(1))/(z(2)-z(1)), (z(3)-x)/(z(3)-(z(2)))]),0);
if(x>=L(1)&& x<=L(3))
Belong = [Belong 'L '];
MF1= [MF1 MF(x,L)] ;
end
if(x>=M(1)&& x<=M(3))
Belong = [Belong 'M '];
MF1= [MF1 MF(x,M)] ;
end
if(x>=H(1)&& x<=H(3))
Belong = [Belong 'H '];
MF1= [MF1 MF1(x,H)] ;
end
end
and in this way the output is:
is this what you need?
  5 Comments
rumin diao
rumin diao on 23 Aug 2022
your code in the third part of the function may be wrong, you may want:
if(x>=H(1)&& x<=H(3))
Belong = [Belong 'H '];
MF1= [MF1 MF(x,H)] ;
end

Sign in to comment.

Categories

Find more on Fuzzy Inference System Modeling 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!

Translated by