%%
clc
clear

subject_options;


k=1;
for sb=1:26
    if ~(strcmp(subjname{sb},'sub14')||strcmp(subjname{sb},'sub24'))
        load([matpath,'timelock_planar_',subjname{sb},'_200Hz_ica.mat']);
        exp{k} = avg_timelock_exp_p;
        unexp{k} = avg_timelock_unexp_p;        
        difference = avg_timelock_exp_p;
        difference.avg = avg_timelock_unexp_p.avg - avg_timelock_exp_p.avg;
        undiff{k} = difference;
        k=k+1;
    end
end

exp_cell_array = [];
unexp_cell_array = [];
diff_cell_array =[];

for i = 1: 24
    exp_cell_array   = [exp_cell_array, ', exp{',num2str(i),'}'];
    unexp_cell_array = [unexp_cell_array, ', unexp{',num2str(i),'}'];
    diff_cell_array  = [diff_cell_array, ',  undiff{',num2str(i),'}'];
end

eval(['g_exp=ft_timelockgrandaverage([]',exp_cell_array,')']);
eval(['g_unexp=ft_timelockgrandaverage([]',unexp_cell_array,')']);
eval(['g_diff=ft_timelockgrandaverage([]',diff_cell_array,')']);

%%

timeROI = [0.4 0.5];
figure;
cfg = [];
cfg.xlim = timeROI;
cfg.zlim = [-1e-13 1e-13];
cfg.layout = 'CTF275.lay';
cfg.colorbar = 'yes';
cfg.markersymbol = '.';
ft_topoplotER(cfg,g_unexp);
colormap(jet)
set(gca,'FontSize',26)

%%
figure
cfg = [];
cfg.xlim = timeROI;
cfg.zlim = [-1e-13 1e-13];
cfg.layout = 'CTF275.lay';
cfg.colorbar = 'yes';
cfg.markersymbol = '.';
ft_topoplotER(cfg,g_exp);
colormap(jet)

figure
cfg = [];
cfg.xlim = timeROI;
cfg.zlim = [-2e-14 2e-14];
cfg.layout = 'CTF275.lay';
cfg.colorbar = 'yes';

cfg.markersymbol = '.';
ft_topoplotER(cfg,g_diff);
colormap(jet)

