
clc
close all

% Definition of integer values
itg.fig = 1;
itg.lab = 1;
itg.fda = 1;
itg.axe = 1;
itg.ann = 1;

dec.sp = 21;

% Definition of figure and values
fig.dimw12 = 12.3;  % 12.5 for ESCAPE
fig.dimh12 = 5.5;
fig.dimw21 = 8.4;
fig.dimh21 = 12;
fig.dimw = 8.4;
fig.dimh = 6;
fig.Font = [10 8];
fig.label = [];
fig.ann   = [];
fig.dat   = [];

if dec.sp == 12
    fig.dimw = fig.dimw12;
    fig.dimh = fig.dimh12;
    ax1 = [.10 .15 .375 .8];
    ax2 = [.6 .15 .375 .8];
elseif dec.sp == 21
    fig.dimw = fig.dimw21;
    fig.dimh = fig.dimh21;
    ax1 = [.15 .55 .775 .4];
    ax2 = [.15 .10 .775 .4];
end
    
for j = 1:n.red
    fig.in(itg.fig) = figure(itg.fig);
    set(fig.in(itg.fig),'units','centimeters','position', [5+itg.fig,5+itg.fig, fig.dimw, fig.dimh]);
    subplot('position',ax1)
    fig.axes(itg.axe) = gca;
%     fig.axes(itg.axe).Position = ax1;
    hold on
    for l = 1:sumpct{end,j}
        fig.dat(itg.fda) = plot(Np.tot(2:n.PLS),cell2mat(norm_loads_mean(1:n.PLS,j,l))); itg.fda = itg.fda+1;
        if j == 1
            fig.label(itg.lab) = ylabel('$\left|\mathbf{w}_i\right|$'); itg.lab = itg.lab+1;
        end
    end
%     fig.dat(itg.fda) = plot([0 opt.Np],opt.normtresh*[1 1],'k--'); itg.fda = itg.fda+1;
%     legend('1','2','3','4','5','6','7','8','9')
    fig.axes(itg.axe).YScale = 'log';
%     fig.axes(itg.axe).XScale = 'log';
    itg.axe = itg.axe+1;
    
    subplot('position',ax2)
    fig.axes(itg.axe) = gca;
%     fig.axes(itg.axe).Position = ax2;
    fig.dat(itg.fda) = plot(Np.tot(2:n.PLS),cell2mat(norm_comb_mean_1(2:n.PLS,j)),'k'); itg.fda = itg.fda+1;
    hold on
    fig.dat(itg.fda) = plot(Np.tot(2:n.PLS),cell2mat(norm_comb_mean_2(2:n.PLS,j)),'k--'); itg.fda = itg.fda+1;
    fig.dat(itg.fda) = plot(Np.tot(2:n.PLS),cell2mat(norm_comb_mean_i(2:n.PLS,j)),'r'); itg.fda = itg.fda+1;
    fig.dat(itg.fda) = plot(Np.tot(2:n.PLS),cell2mat(norm_comb_mean_f(2:n.PLS,j)),'r--'); itg.fda = itg.fda+1;
%     fig.dat(itg.fda) = plot([0 opt.Np],opt.normtresh*[1 1],'k--'); itg.fda = itg.fda+1;
    if j == 1
        fig.label(itg.lab) = ylabel('$\left|\mathbf{w}_{1:i}\right|$'); itg.lab = itg.lab+1;
    end
    fig.axes(itg.axe).YScale = 'log';
    itg.axe = itg.axe+1;
    itg.fig = itg.fig+1;
    
    fig.in(itg.fig) = figure(itg.fig);
    for l = 1:n.in
        subplot(2,ceil(n.in/2),l)
        title(['Component ',num2str(l)])
        plot(Np.tot,diff_mat{l,j}')
        ylim(opt.normtresh*[-1 1])
    end
    subplot(2,ceil(n.in/2),l+1)
    plot(Np.tot,cell2mat(sumpct))
    itg.fig = itg.fig+1;
end


% set(fig.ann(1:2), 'Interpreter', 'Latex');
% set(fig.ann(1:2), 'Fontsize', 10);
% set(fig.ann(1:2), 'LineStyle', 'none');
set(fig.label, 'Fontsize', fig.Font(1));
set(fig.label, 'Interpreter', 'Latex');
set(fig.axes,'FontSize', fig.Font(2));
% set(fig.axes,'Legend.FontSize', fig.Font(2));
set(fig.axes,'Box','on');
set(fig.axes,'TickLabelInterpreter', 'Latex');
set(fig.axes,'LineWidth',.75);
set(fig.axes,'XMinorTick', 'on');
set(fig.axes,'YMinorTick', 'on');
set(fig.dat,'LineWidth',.75)
% fig.axes(2).FontSize = 6;
% fig.axes(end).Legend.FontSize = 8;

