-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathaddEEGEvents.m
63 lines (57 loc) · 2.46 KB
/
addEEGEvents.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
function [EEG, classCount] = addEEGEvents(EEG,targetChar,targetNum, classifiers, newLetters)
%addEEGEvents adds events to an EEGLAB dataset based on the events
%following a target event. This function is specially useful if you
%want to select only stimulus-locked events followed by a correct response.
%The function addes new event to the dataset at the same time point of the
%target event for each target event followed by a classifier. The event code
%of the new event is the letter of the classifier and the number of the
%target event (e.g. 'S 5' followed by classifier 1 becomes 'R 5').
% Input:
% EEG - EEGLAB dataset structure
% targetChar - target event as character (e.g. 'S 5').
% targetNum - target event as integer (e.g. 5).
% classifiers - classifiying events as cell (e.g. {'S 1', 'S 2', 'S 3'}).
% newLetters - new letter for each classifier as cell (e.g. {'R', 'F' 'M'}).
%
% Output:
% EEG - updated EEG dataset (e.g. correctly responded 'S 5' becomes
% 'R 5').
% classCount - vector containing how often each classifier followed a
% a target event.
%
% Example:
% targetChar = 'S 5'; % Stimulus-locked event
% targetNum = 5;
% classifiers = {'S 1', 'S 2', 'S 3'}; % Event codes for correct, false
% % and missed responses
% newLetters = {'R', 'F', 'M'}; % R for right, F for false and....
% [EEG, classCount] = addEEGEvents(EEG,targetChar,targetNum, classifiers, newLetters)
%
% Author: Jörn Alexander Quent (e-Mail: [email protected])
% Version: 2.0 - 03/17/2016
%% Checking input
if length(classifiers) ~= length(newLetters)
error('A new letter must be provided for each classifier');
end
%% Setting up
numberEvents = length(EEG.event);
classCount = zeros(length(classifiers), 1);
%% Adding new events
for i = 1:numberEvents
if strcmp(EEG.event(i).type, targetChar)
for j = 1:length(classifiers)
if strcmp(EEG.event(i + 1).type, classifiers{j})
classCount(j) = classCount(j) + 1;
EEG.event(end + 1) = EEG.event(i);
EEG.event(end).type = [newLetters{j},' ', num2str(targetNum)];
end
end
end
end
%% Display summary
total = sum(classCount);
fprintf(['Set ',EEG.setname,' contained:\n'])
for j = 1:length(classifiers)
fprintf('Type %d: %d (%d %%)\n', j ,classCount(j), round((classCount(j)/total)*100))
end
end