%% Obtain Intermediate Fuzzy Inference Results
%
% Load FIS.

fis = readfis('tipper');

%
% Evaluate the FIS, and return the intermediate inference results.

[output,fuzzifiedIn,ruleOut,aggregatedOut,ruleFiring] = evalfis(fis,[2 1]);

%
% You can examine the intermediate results to understand or visualize the fuzzy inference process. For example, view the aggregated output fuzzy set, which is the fuzzy set that evalfis defuzzifies to find the output value. Also, plot the defuzzified output value.

outputRange = linspace(fis.output.range(1),fis.output.range(2),length(aggregatedOut))'; 
plot(outputRange,aggregatedOut,[output output],[0 1])
xlabel('Tip')
ylabel('Output Membership')
legend('Aggregated output fuzzy set','Defuzzified output')

%
% The length of aggregatedOutput corresponds to the number of sample points used to discretize output fuzzy sets.
% Copyright 2017 The MathWorks, Inc.