% clear the memory clear; % close all open files and windows close all; % clear the command console clc; % create a loop that loads the 10 subject files and puts them into the % variable erpData for i = 1:10 fileName = ['Subject ' num2str(i) '.mat']; load(fileName); erpData(:,:,:,i) = ERP.data; end % check the matrix dimensions size(erpData) % take the average across participants grandERP = mean(erpData,4); % plot the grand average % let's plot the P300, we will use channel Pz subplot(1,3,1); erpChannel = 52; % Pz plot(ERP.times,grandERP(erpChannel,:,1)); hold on; plot(ERP.times,grandERP(erpChannel,:,2)); % create difference waveforms differenceERPs = squeeze(erpData(:,:,1,:) - erpData(:,:,2,:)); % take the mean across participants grandDifference = mean(differenceERPs,3); % plot the difference subplot(1,3,2); plot(ERP.times,grandDifference(erpChannel,:)); % find the maximal value [peakValue peakPoint] = max(grandDifference(erpChannel,:)); % extract the peak data peakData = squeeze(differenceERPs(erpChannel,peakPoint-20:peakPoint+20,:)) peakData = mean(peakData,1); % ttest to see if a P300 is present [h,p,ci,stats] = ttest(peakData); % and we can plot the P300 topography subplot(1,3,3); doPlot2DTopo(grandDifference(:,peakPoint),ERP.chanlocs);