Plot fuzzy membership function for specified parameters (x, u(x))
15 views (last 30 days)
Show older comments
Since I'm new to Fuzzy Logic and Matlab too, I have two fuzzy subsets and it's membership functions in a picture, and I need to plot the graphs from the membership functions with Matlab. I've already found the waty to plot the graphs, in this doc from Matlab official site: https://www.mathworks.com/help/fuzzy/plotmf.html
But I don't know how to create the .fis file (Fuzzy inference system), containing the fuzzy subsets, just so I can read it in a new code and plot the graph, like in:
fis = readfis('tipper'); #I need to create this.
plot(xOut(:,2),yOut(:,2))
xlabel('food')
ylabel('delicious membership')
Here are the fuzzy subsets I need to transform in a fis file:
And the original set is U = {0, 1, 2, 3, 4, 5, 6, 7, 9}, as seen in the picture.
Please don't send me to a similar question beacause I really need help with this case. What should I do?
0 Comments
Answers (1)
Sam Chak
on 16 Sep 2022
One proper way to plot the membership functions (MFs) is to create custom MFs based on the given fuzzy sets.
Since this is not possible to save customMF.m online, the Logistic function (aka Sigmoidal MF) from the toolbox can be used to approximate the fuzzy sets.
% Data Sets
u = (0:9)';
A = [0.0 0.0 0.1 0.2 0.3 0.8 0.9 1.0 1.0 1.0]';
B = [1.0 1.0 0.9 0.8 0.7 0.5 0.4 0.2 0.2 0.0]';
% Curve-fitting
fo = fitoptions('Method','NonlinearLeastSquares',...
'Lower',[-10, -10],...
'Upper',[ 10, 10],...
'StartPoint', [1 1]);
ft = fittype('1/(1 + exp(-a*(x - c)))', 'options', fo);
[sigmA, gof] = fit(u, A, ft)
[sigmB, gof] = fit(u, B, ft)
figure(1)
plot(u, A, '.'), hold on
plot(sigmA, 'r'), hold off
grid on, xlabel('u'), ylabel('A(u)')
legend('Set A', 'Fitted Sigmoid', 'location', 'best')
figure(2)
plot(u, B, '.'), hold on
plot(sigmB, 'r'), hold off
grid on, xlabel('u'), ylabel('B(u)')
legend('Set B', 'Fitted Sigmoid', 'location', 'best')
% Creating FIS and putting the input MFs into FIS
fis = mamfis('Name', "user_FIS");
% Fuzzy Input
fis = addInput(fis, [0 9], 'Name', 'U');
fis = addMF(fis, 'U', 'sigmf', [sigmB.a sigmB.c], 'Name', 'LO');
fis = addMF(fis, 'U', 'sigmf', [sigmA.a sigmA.c], 'Name', 'HI');
% Plot membership functions
figure(3)
plotmf(fis, 'input', 1), grid on, title('U')
0 Comments
See Also
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!