% This function is used to plot the results for the example - 
% 'CAN Message Reception Behavior in Simulink'.
% This is configured to execute in the StopFunction callback of the model-
% CanReceiveModel.slx, so that it is executed when the model stops simulation.

function plotResults(~)

% Read and plot the signal data received outside the function-call subsystem.
rxOutFuncSubsystem = evalin('base','rxOutFuncSubsystem');
x = rxOutFuncSubsystem.Time;
y = rxOutFuncSubsystem.Data;
plot(x,y,'-x')
hold on

% Read and plot the signal data received inside the function-call subsystem.
rxInFuncSubsystem = evalin('base','rxInFuncSubsystem');
x = rxInFuncSubsystem.Time;
y = rxInFuncSubsystem.Data;
plot(x,y,'-o')
hold off

% Add labels the plot.
xlabel("TimeStamp");
ylabel('Signal Value');
legend('Signal Outside','Signal Inside',"Location","northwest");
legend("boxoff");

end