function y = custdfuz(x,membershipValueOfX)
%% CUSTDFUZ Customized defuzzification function for CUSTTIP.FIS

% Copyright 1996 - 2017 The MathWorks, Inc.

area = cast(0,'like',x);
for i = 1:numel(membershipValueOfX)
    area(1) = area(1) + membershipValueOfX(i);
end

y = cast(0,'like',x);
for i = 1:numel(membershipValueOfX)
    y(1) = y(1) + x(i)*membershipValueOfX(i);
end
y(1) = y(1)*(1/area(1));

end