clear
close all
f=figure(6);
tiledlayout(5,4);
PWD=pwd;
cd ..
cd('Output CSVs')
DataSets={'Fig5and6_Awake','Fig5and6_Ana'};
TitleName={'N_N_P_Y','[CA_N_P_Y]','[NPY]','[NPY_v_s_m]','N_N_O','[CA_N_O]',...
    '[NO]','[NO_v_s_m]','Vessel Response'};
PlotStyle={'r-','k-'};
YLimits=[-1 1.05;0 2;-3 60;0.95 1.05;-1 1.05;0 2; 0.95 1.08;0.95 1.08;-5 15];
FontSize=6;
for i=1:length(DataSets)
    T=readtable(strcat('sten2020_NVC_main_data_',DataSets{i},'.csv'));
    %8=CA_NO, 7=CA_NPY, 48=N_NO, 50=N_NPY, 54=NO, 56=NO_vsm, 58=NPY,
    %60=NPY_vsm, 13=dilation
    %[time, N_NPY, CA_NPY, NPY, NPY_vsm, N_NO, CA_NO, NO, NO_vsm, D]
    PlotData=table2array(T(:,[1,50,9,58,60,48,7,54,56,13]));
    titlecount=0;
    for j=1:8
        if j==1
            nexttile(1+i-1)
            plot(PlotData(:,1),PlotData(:,j+1),PlotStyle{i})
            titlecount=titlecount+1;
            title(TitleName{titlecount},'FontSize',FontSize,'FontWeight','Bold') 
            ylabel('Cell Activity','FontSize',FontSize,'FontWeight','Bold') 
            xlabel('Time (sec)','FontSize',FontSize,'FontWeight','Bold')
            ylim([YLimits(j,1) YLimits(j,2)])
            xlim([-1 60])
            hold on
            if i==1
                text(17,2,'\itAwake','Color','red')
            else
                text(-4,2,'\itDuring Anesthesia','Color','black')
            end
        elseif j<=4
            nexttile(4*j-3+i-1)
            plot(PlotData(:,1),PlotData(:,j+1)./PlotData(1,j+1),PlotStyle{i})
            titlecount=titlecount+1;
            title(TitleName{titlecount},'FontSize',FontSize,'FontWeight','Bold')
            ylabel('Normalized Response','FontSize',FontSize,'FontWeight','Bold')
            xlabel('Time (sec)','FontSize',FontSize,'FontWeight','Bold')
            ylim([YLimits(j,1) YLimits(j,2)])
            xlim([-1 60])
        elseif j==5
            nexttile(3+i-1)
            plot(PlotData(:,1),PlotData(:,j+1),PlotStyle{i})
            titlecount=titlecount+1;
            title(TitleName{titlecount},'FontSize',FontSize,'FontWeight','Bold') 
            ylabel('Cell Activity','FontSize',FontSize,'FontWeight','Bold') 
            xlabel('Time (sec)','FontSize',FontSize,'FontWeight','Bold')
            ylim([YLimits(j,1) YLimits(j,2)])
            xlim([-1 60])
            hold on
            if i==1
                text(17,2,'\itAwake','Color','red')
            else
                text(-4,2,'\itDuring Anesthesia','Color','black')
            end
        else
            nexttile(4*j-3-14+i-1)
            plot(PlotData(:,1),PlotData(:,j+1)./PlotData(1,j+1),PlotStyle{i})
            titlecount=titlecount+1;
            title(TitleName{titlecount},'FontSize',FontSize,'FontWeight','Bold') 
            ylabel('Normalized Response','FontSize',FontSize,'FontWeight','Bold')
            xlabel('Time (sec)','FontSize',FontSize,'FontWeight','Bold')
            ylim([YLimits(j,1) YLimits(j,2)])
            xlim([-1 60])
        end
    end
    nexttile(18,[1,2])
    plot(PlotData(:,1),PlotData(:,10),PlotStyle{i})
    hold on
    title(TitleName{9},'FontSize',FontSize,'FontWeight','Bold') 
    ylabel('\Delta Dilation (%)','FontSize',FontSize,'FontWeight','Bold')
    xlabel('Time (sec)','FontSize',FontSize,'FontWeight','Bold')
    ylim([YLimits(9,1) YLimits(9,2)])
    xlim([-1 60])
    leg=legend('Awake Condition','Anesthesia Condition');
    set(leg,'Location','NorthEast','FontSize',FontSize)
end

cd(PWD)
set(gcf,'Position',[100 100 700 700])
exportgraphics(f,'Figure6.png','Resolution',600)