How to get the fuzzy value of an input when the crisp value is given

6 views (last 30 days)
I have implemented a fuzzy logic system using toolbox. I want to get the fuzzy value of the crisp input using matlab code. Can you please help me to do this.

Answers (1)

Sam Chak
Sam Chak on 18 Sep 2022
The evalmf() function can used in this situation.
help evalmf
EVALMF Evaluates membership functions. Y = EVALMF(MF,X) Evaluates a type-1 MF with X to generate Y. MF is a scalar or vector of membership function objects and X contains numeric values to be evaluated by MF. If MF - is a scalar, X can be a scalar, vector, or 2D matrix. - is a vector, X must be a scalar or vector. If MF is a scalar membership function object, the size of Y is same as X. In case of a linear membership function, size of Y depends on number of input sets specified in X. If MF is a vector, Y is a matrix of size [M N], where M and N are lengths of MF and X, respectively. [YU,YL] = EVALMF(MF,X) Evaluates a type-2 MF with input values X to generate output values YU and YL, where YU represents the evaluated outputs of the upper membership functions of MF and YL corresponds to the evaluated outputs of the lower membership functions. Examples %% Type-1 membership functions. mf = [fismf(@gaussmf,[1.5 5]) fismf(@trapmf,[3 4 6 7])]; x = (-2:0.1:12)'; y = evalmf(mf,x); plot(x,y) xlabel('Universe of discourse (x)'),ylabel('Type-1 membership value (y)') legend('gaussmf, P=[1.5 5]','trapmf, P=[3 4 6 7]') %% Type-2 membership functions. mf = [fismftype2(@gaussmf,[1.5 5]) fismftype2(@trapmf,[3 4 6 7])]; x = (-2:0.1:12)'; [yu,yl] = evalmf(mf,x); plot(x,[yu;yl]) xlabel('Universe of discourse (x)'),ylabel('Type-2 Membership values (yu,yl)') legend('gaussmf, P=[1.5 5]','trapmf, P=[3 4 6 7]') See also fismf fismftype2 Documentation for evalmf doc evalmf
x = -10:0.1:10;
mf = fismf("pimf", [-9 -7 2 7]);
y = evalmf(mf, x);
% plot membership function
plot(x, y, 'linewidth', 1.5), grid on, ylim([-0.2 1.2]);
xlabel('\it{x}'), ylabel('\mu(\it{x})')
% find the fuzzy value when the crisp value x = 4
fuz_value = evalmf(mf, 4)
fuz_value = 0.6800
xline(4, '--', '4');
yline(fuz_value, '--', sprintf('%.4f', fuz_value));

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!