[Eeglablist] [eeglab] Question about extracting epochs
Scott Makeig
smakeig at ucsd.edu
Thu Apr 8 08:28:16 PDT 2004
Mike - See below...
Mike Cohen wrote:
> Hi, Scott and Arnaud. Thanks for the responses. This script you wrote below
> didn't quite work because there is no EEG.epoch.eventinit_time (at least not
> in my EEGLAB v4.301). I substituted EEG.epoch.eventurevent, but that doesn't
> seem to do the trick either because it lists several epochs as occurring in
> the same order (assuming chronological order of the events is what that
> variable represents). I will presently upload a subsample of my data so you
> can have a look. The file is called cohen_eeg.mat, and it's continuous data,
> 32 channels. You can epoch events [25 26 75 76] from -1.5 seconds to .6
> seconds. If you now look at EEG.epoch.eventtype, the epochs are now sorted
> numerically according to the chosen events. However, this is not the
> chronological order in which they appeared in the continuous data. It would
> be nice to be able to have the epochs be sorted not according to the
> numerical order of the epoching event, but the chronological order in which
> those epochs appear in the experiment.
>
> Thanks in advance for your help,
> Mike Cohen, FAA-certified pilot
> UC Davis Psychology
> http://dynamicmemorylab.org/mcohen
The dataset you uploaded is continuous data - no epochs. ?
The attached version of the eeg_sortepochs() script avoids the problem
you mention (above), and includes some sanity checks and a help message.
Arno, however, could not reprduce your observation on the EEGLAB test
data. Let us know remaining ?? on this, and upload your epoched dataset
if need be.
Scott Makeig
-------------- next part --------------
% eeg_sortepochs() - determine the chronological order of epochs in an EEGLAB dataset
% using the EEG.epoch and EEG.urevent substructures. Specifically,
% uses the fields EEG.epoch().eventlatency, EEG.epoch().urevent, and
% EEG.urevent().latency.
% Usage:
% >> sortidx = eeg_sortepochs(EEG); % returns timne-sorted order only
% >> [sortidx,sorttimes] = eeg_sortepochs(EEG); % also returns the (ur)times
% Input:
% EEG - an EEGLAB dataset structure
% Outputs:
% sortidx - an index to the EEG.epoch array in chronologic order
% of the defining (latency-0) (ur)events.
% sorttimes - the times of occurence (in frames of the original EEG data)
% To convert to times in sec, subtract 1 and divide by EEG.srate
%
% Author: Scott Makeig, SCCN / INC / UCSD April 6, 2004
function [sortidx,sorttimes] = eeg_sortepochs(EEG)
if ~isstruct(EEG)
error('eeg_sortepochs(): input must be an EEG dataset structure');
end
if ~isfield(EEG,'epoch') | isempty(EEG.epoch(1))
error('eeg_sortepochs(): EEG.epoch(1) not present or empty');
end
if ~isfield(EEG.epoch(1),'eventlatency') | isempty(EEG.epoch(1).eventlatency(1))
error('eeg_sortepochs(): EEG.epoch(1).eventlatency not present or empty');
end
if ~isfield(EEG.urevent(1),'latency') | isempty(EEG.urevent(1).latency(1))
error('eeg_sortepochs(): EEG.urevent(1).latency not present or empty');
end
times = zeros(EEG.trials,1);
for k=1:EEG.trials
j = find(cell2mat(EEG.epoch(k).eventlatency) == 0);
urevent = EEG.epoch(k).eventurevent{j}; % cell array -> real value
times(k) = EEG.urevent(urevent).latency; % real value
end
[sorttimes,sortidx] = sort(times); % sort the event times
return
More information about the Eeglablist
mailing list