clear; clc;
warning('off');

sesslist = {'\Non-stimulation\LAMP3_016_190619_180636';
            '\Stimulation\LAMP3_014_190618_163825';};
        
%% parameters
for ip = 1:2
    session = sesslist{ip,1};
    outsr = 100;
    datapath = 'F:\Dropbox\AchProject\Fig3 data\';

    load([datapath,session,filesep,'achplot.mat'],'achplot','speedplot')
    ach{ip,1} = achplot;
    spd{ip,1} = speedplot;
end

figure('Color','white');

yyaxis left;
options.color_area = [243 169 114]./255;    % Orange theme
options.color_line = [236 112  22]./255;
options.alpha      = 0.7;
options.line_width = 2;
options.error      = 'sem';
options.x_axis     = [1:size(ach{1},2)]./outsr-10;
h1 = plot_areaerrorbar(ach{1},options);
hold on;
options.color_area = [128 193 219]./255;    % Blue theme
options.color_line = [ 52 148 186]./255;
options.alpha      = 0.7;
options.line_width = 2;
options.error      = 'sem';
options.x_axis     = [1:size(ach{2},2)]./outsr-10;
h2 = plot_areaerrorbar(ach{2},options);
hold on;

xlim([-10,30]); ylim([-0.05,0.05]); 
yticks([-0.05,0,0.05]); yticklabels([-5,0,5]);
xlabel('Time (s)'); ylabel('dFoverF (%)');

yyaxis right;
options.color_area = [243 169 114]./255/2;    % Orange theme
options.color_line = [236 112  22]./255/2;
options.alpha      = 0.3;
options.line_width = 1;
options.error      = 'sem';
options.x_axis     = [1:size(ach{1},2)]./outsr-10;
h3 = plot_areaerrorbar(spd{1},options);
hold on;
options.color_area = [128 193 219]./255/2;    % Blue theme
options.color_line = [ 52 148 186]./255/2;
options.alpha      = 0.3;
options.line_width = 1;
options.error      = 'sem';
options.x_axis     = [1:size(ach{2},2)]./outsr-10;
h4 = plot_areaerrorbar(spd{2},options);
hold on;

legend([],{});
spdlim = 0.5;
xlim([-10,30]); ylim([0,1]*spdlim); 
yticks([0,0.5,1]*spdlim); yticklabels([0,0.5,1]*spdlim*100)
xlabel('Time (s)'); ylabel('speed cm/s');

pch = patch([0,20,20,0],[-5,-5,5,5],'b');
pch.FaceAlpha = 0.1; pch.EdgeColor = 'none';


legend([h1(1),h2(1),h3(1),h4(1)],{sprintf('ach n=%d',size(ach{1},1)),sprintf('ach n=%d',size(ach{2},1))...
                                    sprintf('spd n=%d',size(spd{1},1)),sprintf('spd n=%d',size(spd{2},1))});


save([datapath,session,filesep,'achplot.mat'],'achplot')




