% Script for generating tv vs ms plots
% written by Chriss Grimholt, January 2012
figure(1);clf;
figure(2);clf;

filenames={'tvYs','tvD'};

colorSet = colormap('lines');

for modelId = 1:4

modelName = {'res0','res1','res8','resInf'};

file = modelName{modelId};

load(file)
tvRes = tvTuning(model(modelId),res.minTuning.tuning);

figure(1)
h=plot(res.minTuning.ms,tvRes(1,:));%[1+res.minTuning.tuning(1,:); ones(1,length(tvRes))]
set(h,'LineWidth',1.5,'color',colorSet(modelId,:))
hold on

figure(2)
k=plot(res.minTuning.ms,tvRes(2,:));%[1+res.minTuning.tuning(1,:); ones(1,length(tvRes))]
set(k,'LineWidth',1.5,'color',colorSet(modelId,:))
hold on
end
saveas(h(1),[filenames{1},'.fig'],'fig')
saveas(k(1),[filenames{2},'.fig'],'fig')
hold off 
%% Plotting

% opens the result figure and adds labels.
% case 1 - setpoint figure, case 2 - disturbance figure.
caseId = 1;



h=open([filenames{caseId},'.fig']);


axis([1.1 3 0 6])

xpos = [2 1.45 1.6 2.5];
ypos = [4.5 1.2 3.5 3.5];
textString = {'$\tau_1/\theta=0$'
              '$\tau_1/\theta=1$'
              '$\tau_1/\theta=8$'
              '$$\tau_1/\theta=\infty$'};
          
for i = 1:length(textString);
    [figx figy] = dsxy2figxy(gca, xpos(i), ypos(i));
    textBox = annotation('textbox',[figx, figy, .07, .05],'string',textString{i},'interpreter','latex','fontsize',14,'color',colorSet(i,:),'FitBoxToText','on','LineStyle','non');    
end
          
          

xlab=xlabel('Robustness, $M_s$');%,'interpreter','latex');
if caseId == 1
    ylab=ylabel('Total variation, TV$_s(u)$');%)','interpreter','latex');
elseif caseId == 2
    ylab=ylabel('Total variation, TV$_d(u)$');%)','interpreter','latex');
end



set(xlab,'interpreter','latex','fontsize',14)
set(ylab,'interpreter','latex','fontsize',14)
%set(ylab,) 

%
%saveas(h,['tv',filenames{caseId},'2.eps'],'psc2')
