% Code to plot simulation results from sh_testrig_constant_chamber
%% Plot Description:
%
% The plot below shows how the pressure in a constant volume chamber varies
% with time.

% Copyright 2015 The MathWorks, Inc.

% Generate simulation results if they don't exist
if ~exist('simlog_sh_testrig_constant_chamber', 'var')
    sim('sh_testrig_constant_chamber')
end

% Reuse figure if it exists, else create new figure
if ~exist('h1_sh_testrig_constant_chamber', 'var') || ...
        ~isgraphics(h1_sh_testrig_constant_chamber, 'figure')
    h1_sh_testrig_constant_chamber = figure('Name', 'sh_testrig_constant_chamber');
end
figure(h1_sh_testrig_constant_chamber)
clf(h1_sh_testrig_constant_chamber)

% Get simulation results
simlog_t = simlog_sh_testrig_constant_chamber.Constant_Volume_Chamber.A.p.series.time;
simlog_chapA = simlog_sh_testrig_constant_chamber.Constant_Volume_Chamber.A.p.series.values('Pa');

temp_theorypA =get(logsout_sh_testrig_constant_chamber,'Theory');    % Simulink

% Plot results
plot(simlog_t, simlog_chapA, 'LineWidth', 3)
hold on
plot(simlog_t, temp_theorypA.Values.Data,'Color','c', 'LineWidth', 2,'LineStyle','--')
hold off
grid on
title('Chamber Pressure')
ylabel('Pressure (Pa)')
legend({'Model','Theory'},'Location','Best');
xlabel('Time (s)')

% Remove temporary variables
clear simlog_t simlog_chapA temp_theorypA simlog_handles
