clear all,clc
sim('pi_controllers')
% Kc=-25;%bar^-1;
% taui=10;%s
%tout=tout+10;
P1=P1-1.013;
sp=sp-1.013;
z=z*100;

tid_reg_paa=120;
index_reg_paa=find(abs(tout-tid_reg_paa)==min(abs(tout-tid_reg_paa)));
tid_reg_av=480;
index_reg_av=find(abs(tout-tid_reg_av)==min(abs(tout-tid_reg_av)));
sp=sp(index_reg_paa:index_reg_av);
tid_sp=tout(index_reg_paa:index_reg_av);


figure(1)
subplot(2,1,1)
plot(tout,P1)
hold on
plot(tid_sp,sp,'r-')
ylabel('P_1 [barg]')
legend('P_1 [barg]','SP [barg]',0)
hold off


subplot(2,1,2)
plot(tout,z)
xlabel('tid [s]')
ylabel('Ventilåpning %')
% g=gcf;
% set(g,'PaperUnits','centimeters','PaperType','A4')
% opts = struct('FontMode','fixed','FontSize',9,'Width',15,'Color','rgb');
% exportfig(g,'enkel_regulering_P1_z_30.eps',opts)
% 
% figure(2)
% subplot(4,1,1)
% plot(tout,P2)
% ylabel('P_2 [barg]')
% 
% subplot(4,1,2)
% plot(tout,W)
% ylabel('W [kg/s]')
% 
% subplot(4,1,3)
% plot(tout,Q)
% ylabel('Q  [10^{-4} m^3/s]')
% 
% subplot(4,1,4)
% plot(tout,z)
% xlabel('tid [s]')
% ylabel('z [%]')
% g=gcf;
% set(g,'PaperUnits','centimeters','PaperType','A4')
% opts = struct('FontMode','fixed','FontSize',9,'Width',15,'Color','rgb');
% exportfig(g,'enkel_regulering_data_z_30.eps',opts)