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?
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
Rik
2022 年 8 月 23 日
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?
回答 (1 件)
rumin diao
2022 年 8 月 23 日
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 件のコメント
rumin diao
2022 年 8 月 23 日
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
参考
カテゴリ
Help Center および File Exchange で Fuzzy Logic in Simulink についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!