
% point corresponding to 100 ms
latency = 0.100;
pt100 = round((latency-EEG.xmin)*EEG.srate);

% find the equivalent dipole position for the scalp map at this timepoint
erp = mean(EEG.data(:,:,:), 3);
EEG = pop_dipfit_settings(EEG);
[ dipole model TMPEEG] = dipfit_erpeeg(erp(:,pt100), EEG.chanlocs, 'settings', EEG.dipfit, 'threshold', 100);

% show dipole information (spherical or MNI coordinate based on the model selected)
dipole

% plot the dipole in 3-D
pop_dipplot(TMPEEG, 1, 'normlen', 'on');

% plot the dipole plus the scalp map
figure; pop_topoplot(TMPEEG,0,1, [ 'ERP 100ms, fit with a single dipole (RV ' num2str(dipole(1).rv*100,2) '%)'], 0, 1);

