figure(1);clf
stdFont = 20;
tauFont = 20;
msFont = 45;
msSet = [1.2 1.59 2.0];
msString={'$M_s = 1.2$', '$M_s=1.59$','$M_s=2.0$'};
for j = 1:3
    
files = {'res0.mat'
         'res1.mat'
         'res8.mat'
         'resInf.mat'};
     tuning = [];
     
for i =  1:length(files)
    load(files{i})
    index = find(res.minTuning.ms > msSet(j));
    index(1)
    tuning{i} = res.minTuning.tuning(:,index(1));
end


%tuning = {0.2   .32]
%          [.54 1.1]
%          [3.46 4]
%          [0.41 6.3]};
colorSet = colormap('lines');



dTime = 20;
stopTime = 40;
figure(1)
 subplot(3,2,1+2*(j-1))
%figure(1)
r = plot([0 40],[1 1]);
set(r, 'Color', [0 0 0], 'LineWidth', 1.5,'LineStyle','--');
axis([0 40 0 4])
hold on
annotationString  = {'$\tau_1=0$','$\tau_1=1$','$\tau_1=8$','$\tau_1=\infty$'};

% Ms
xpos=[16 24.5 30 28];
ypos=[1, 1.2, .4, 2];
xpos2=[17 -0.3 2.5 10];
ypos2=[-0.2, 0.8, 3, -1.3];

%Ms
% xpos=[16 24.5 30 28];
% ypos=[1, 1.2, .4, 2];
% xpos2=[17 -0.3 2.5 10];
% ypos2=[-0.2, 0.8, 3, -1.3];
for i = 1:length(tuning)
    
    subplot(3,2,1+2*(j-1))
    gp = model(i);
    gc = controller(tuning{i}(1),tuning{i}(2));
    sim('simModel')
    r = plot(t,y);
    set(r, 'Color', colorSet(i,:), 'LineWidth', 1.5);
    axis([0 40 0 4])
    [figx figy] = dsxy2figxy(gca, xpos(i), ypos(i));
    textBox = annotation('textbox',[figx, figy, .07, .05],'string',annotationString{i},'interpreter','latex','fontsize',tauFont,'color',colorSet(i,:),'FitBoxToText','on','LineStyle','non');    
    hold on
    
    subplot( 3,2,2*j)
    r = plot(t,u);
    set(r, 'Color', colorSet(i,:), 'LineWidth', 1.5);
    axis([0 40 -2 5])
    [figx figy] = dsxy2figxy(gca, xpos2(i), ypos2(i));
    textBox = annotation('textbox',[figx, figy, .07, .05],'string',annotationString{i},'interpreter','latex','fontsize',tauFont,'color',colorSet(i,:),'FitBoxToText','on','LineStyle','non');    
    hold on
   
end
subplot(3,2,1+2*(j-1))
[figx figy] = dsxy2figxy(gca, 3, 3);
ylabel('Output, $y$', 'interpreter','latex','fontsize',stdFont);
textBox = annotation('textbox',[figx, figy, .07, .03],'string',msString{j},'interpreter','latex','fontsize',msFont,'color',[0 0 0],'FitBoxToText','on','LineStyle','non');    
subplot( 3,2,2*j)
ylabel('Input, $u$', 'interpreter','latex','fontsize',stdFont)
textBox = annotation('textbox',[0.8, figy, .07, .03],'string',msString{j},'interpreter','latex','fontsize',msFont,'color',[0 0 0],'FitBoxToText','on','LineStyle','non');    
end

subplot(3,2,5); xlabel('Time, $t$', 'interpreter','latex','fontsize',stdFont);
subplot(3,2,6); xlabel('Time, $t$', 'interpreter','latex','fontsize',stdFont);

%%
%saveas(r,'stepResponcsePO159Final.eps','psc2')