Musings‎ > ‎

scatter_ERP

%% load the data

% go to the location where the data are located, then:
load scatter_data

condition1_mean = squeeze(mean(condition1.individual));
condition2_mean = squeeze(mean(condition2.individual));

%% find peaks and latencies

for sb = 1:16 % loop over subjects

    % find peaks or troughs 
    N1_stim1_cond1_peak(sb) = abs(max(N1_stim1_condition1(sb,:))); 
    % find peak/trough latency
    N1_stim1_cond1_latency(sb) = N1_stim1_time(find(N1_stim1_condition1(sb,:) == N1_stim1_cond1_peak(sb))); 

    N1_stim1_cond2_peak(sb) = abs(max(N1_stim1_condition2(sb,:)));
    N1_stim1_cond2_latency(sb) = N1_stim1_time(find(N1_stim1_condition2(sb,:) == N1_stim1_cond2_peak(sb)));

    
    N1_stim2_cond1_peak(sb) = abs(max(N1_stim2_condition1(sb,:)));
    N1_stim2_cond1_latency(sb) = N1_stim2_time(find(N1_stim2_condition1(sb,:) == N1_stim2_cond1_peak(sb)));

    N1_stim2_cond2_peak(sb) = abs(max(N1_stim2_condition2(sb,:)));
    N1_stim2_cond2_latency(sb) = N1_stim2_time(find(N1_stim2_condition2(sb,:) == N1_stim2_cond2_peak(sb)));

end

%% difference waves and dispersion

condition_difference = (condition2.individual - condition1.individual);
mean_condition_difference = mean(condition_difference);
stdev_difference = std(condition_difference);

for sb = 1:16 % loop over subjects

    difference_wave_peak(sb) = abs(max(condition_difference(sb,find(time==500):end)));
    difference_wave_latency(sb) = condition1.time(find(condition_difference(sb,:) == difference_wave_peak(sb)));

 end

%% plot

% to plot this you will also need the boundedline function, to be found here.
% https://uk.mathworks.com/matlabcentral/fileexchange/27485-boundedline-m

figure(1);clf; set(gcf,'color', 'w', 'Position', [687 125 539 641]); hold on

boundedline(time, mean_condition_difference, stdev_difference, 'k', 'transparency', 0.2)
plot(time, mean_condition_difference, 'k', 'Linewidth', 2)

plot(N1_stim1_cond1_latency, N1_stim1_cond1_peak, 'o', 'MarkerEdgeColor', [0.4,0.4,1],'MarkerFaceColor', [0.6,0.6,1], 'MarkerSize', 4)
plot(N1_stim1_cond2_latency, N1_stim1_cond2_peak, 'o', 'MarkerEdgeColor', [1,0.4,0.4],'MarkerFaceColor', [1,0.6,0.6], 'MarkerSize', 4)

plot(N1_stim2_cond1_latency, N1_stim2_cond1_peak, 'o', 'MarkerEdgeColor', [0.4,0.4,1],'MarkerFaceColor', [0.6,0.6,1], 'MarkerSize', 4)
plot(N1_stim2_cond2_latency, N1_stim2_cond2_peak, 'o', 'MarkerEdgeColor', [1,0.4,0.4],'MarkerFaceColor', [1,0.6,0.6], 'MarkerSize', 4)

plot(difference_wave_latency, difference_wave_peak, '.', 'MarkerEdgeColor', [0,0,0],'MarkerSize',6)

plot(time,condition1_mean, 'b', 'LineWidth', 2)
plot(time,condition2_mean, 'r', 'LineWidth', 2)

line([0 0], [-50 200], 'Color', [0.7 0.7 0.7])
line([500 500], [-50 200], 'Color', [0.7 0.7 0.7])
line([-100 1000], [0 0], 'Color', 'k')

xlim([-100 1000]); box off
set(gca, 'Xtick', [-100:100:1000])
set(gca,'Xticklabel',{[],0,100,200,300,400,500,600,700,800,900,[]})
set(gca,'Yticklabel',{[],0,50,100,150,200,250,300,[]})
xlabel('Time (msec)', 'FontSize', 12)
ylabel('Field Strength (fT)', 'FontSize', 12)

%%
Comments