Home > matlabmk > list_event_types.m

list_event_types

PURPOSE ^

list_event_types() - Tallies the set of event "types" in an EEGLAB EEG

SYNOPSIS ^

function [types type_count]=list_event_types(EEG_or_fname,timelock_only)

DESCRIPTION ^

 list_event_types() - Tallies the set of event "types" in an EEGLAB EEG
                      variable and the number of times each event occurs.

 Usage:
  >>  [types type_count]=list_event_types(EEG_or_fname,timelock_only)


 Required Input:
   EEG_or_fname - EEGLAB EEG struct variable containing epoched or 
                  continuous EEG data or the filename of a set file
                  that contains such an EEG struct variable.


 Optional Input:
   timelock_only - [1 or 0] If 1, only the event types of events to which
                   an epoch is time locked will be tallied (i.e., events 
                   that occur at 0 ms in the epoch). If 0, all events 
                   types are tallied. This optional input is only relevant
                   to epoched data sets. {default: 1}

 Outputs:
   types       - Cell array of the set of event types found  

   type_count  - Number of instances of each type found. Note that
                 type_count(a) is the count for types{a}.

 Author:
 David Groppe
 Kutaslab, 10/2010

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 % list_event_types() - Tallies the set of event "types" in an EEGLAB EEG
0002 %                      variable and the number of times each event occurs.
0003 %
0004 % Usage:
0005 %  >>  [types type_count]=list_event_types(EEG_or_fname,timelock_only)
0006 %
0007 %
0008 % Required Input:
0009 %   EEG_or_fname - EEGLAB EEG struct variable containing epoched or
0010 %                  continuous EEG data or the filename of a set file
0011 %                  that contains such an EEG struct variable.
0012 %
0013 %
0014 % Optional Input:
0015 %   timelock_only - [1 or 0] If 1, only the event types of events to which
0016 %                   an epoch is time locked will be tallied (i.e., events
0017 %                   that occur at 0 ms in the epoch). If 0, all events
0018 %                   types are tallied. This optional input is only relevant
0019 %                   to epoched data sets. {default: 1}
0020 %
0021 % Outputs:
0022 %   types       - Cell array of the set of event types found
0023 %
0024 %   type_count  - Number of instances of each type found. Note that
0025 %                 type_count(a) is the count for types{a}.
0026 %
0027 % Author:
0028 % David Groppe
0029 % Kutaslab, 10/2010
0030 
0031 %%%%%%%%%%%%%%%% REVISION LOG %%%%%%%%%%%%%%%%%
0032 % 12/16/2010-Can now handle continuous data
0033 %
0034 % 7/10/2011-Can now deal with event types that aren't strings
0035 
0036 function [types type_count]=list_event_types(EEG_or_fname,timelock_only)
0037 
0038 if nargin<2,
0039    timelock_only=1; 
0040 end
0041 
0042 if ischar(EEG_or_fname),
0043     EEG=pop_loadset(EEG_or_fname);
0044 else
0045     EEG=EEG_or_fname;
0046     clear EEG_or_fname;
0047 end
0048 
0049 %% Modicum of Error Checking
0050 if isempty(EEG.epoch),
0051     %Continuous data
0052     fprintf('set file contains continuous EEG data.\n');
0053     n_ev=length(EEG.event);
0054     n_types=0;
0055     types=[];
0056     type_count=[];
0057     for a=1:n_ev,
0058         ev_type=EEG.event(a).type;
0059         if ~isstr(ev_type)
0060             ev_type=num2str(ev_type);
0061         end
0062         if isempty(types),
0063             tf=0;
0064         else
0065             [tf, loc]=ismember(ev_type,types);
0066         end
0067         if tf
0068             %type has already been encountered, increment counter
0069             type_count(loc)=type_count(loc)+1;
0070         else
0071             %novel type
0072             n_types=n_types+1;
0073             types{n_types}=ev_type;
0074             type_count(n_types)=1;
0075         end
0076     end
0077 else
0078     %Epoched data
0079     fprintf('set file contains epoched EEG data.\n');
0080     n_ep=length(EEG.epoch);
0081     n_types=0;
0082     types=[];
0083     type_count=[];
0084     if timelock_only,
0085         for a=1:n_ep,
0086             if iscell(EEG.epoch(a).eventtype),
0087                 %if only one event per epoch, a string is used instead
0088                 %of a cell array
0089                 n_type_this_ep=length(EEG.epoch(a).eventtype);
0090             else
0091                 n_type_this_ep=1;
0092             end
0093             for b=1:n_type_this_ep,
0094                 if iscell(EEG.epoch(a).eventlatency),
0095                     %if only one event per epoch, a scalar is used instead
0096                     %of a cell array
0097                     ev_latency=EEG.epoch(a).eventlatency{b};
0098                     ev_type=EEG.epoch(a).eventtype{b};
0099                 else
0100                     ev_latency=EEG.epoch(a).eventlatency(b);
0101                     ev_type=EEG.epoch(a).eventtype;
0102                 end
0103                 
0104                 if ~ev_latency,
0105                     %only log event types for events that the epoch is
0106                     %timelocked to
0107                     if isempty(types)
0108                         tf=0;
0109                     else
0110                         [tf loc]=ismember(ev_type,types);
0111                     end
0112                     if tf
0113                         %type has already been encountered, increment counter
0114                         type_count(loc)=type_count(loc)+1;
0115                     else
0116                         %novel type
0117                         n_types=n_types+1;
0118                         if iscell(ev_type),
0119                             types{n_types}=ev_type{1};
0120                         else
0121                             types{n_types}=ev_type;
0122                         end
0123                         type_count(n_types)=1;
0124                     end
0125                 end
0126             end
0127         end
0128     else
0129         for a=1:n_ep,
0130             if iscell(EEG.epoch(a).eventtype),
0131                 %if only one event per epoch, a string is used instead
0132                 %of a cell array
0133                 n_type_this_ep=length(EEG.epoch(a).eventtype);
0134             else
0135                 n_type_this_ep=1;
0136             end
0137             for b=1:n_type_this_ep,
0138                 if iscell(EEG.epoch(a).eventlatency),
0139                     %if only one event per epoch, a string is used instead
0140                     %of a cell array
0141                     ev_type=EEG.epoch(a).eventtype{b};
0142                 else
0143                     ev_type=EEG.epoch(a).eventtype;
0144                 end
0145                 [tf loc]=ismember(ev_type,types);
0146                 if tf
0147                     %type has already been encountered, increment counter
0148                     type_count(loc)=type_count(loc)+1;
0149                 else
0150                     %novel type
0151                     n_types=n_types+1;
0152                     types{n_types}=ev_type;
0153                     type_count(n_types)=1;
0154                 end
0155             end
0156         end
0157     end
0158 end
0159 
0160 for a=1:n_types,
0161     fprintf('Event Type: ''%s'' (occurences=%d)\n',types{a},type_count(a));
0162 end

Generated on Tue 10-May-2016 16:37:45 by m2html © 2005