-
Notifications
You must be signed in to change notification settings - Fork 3
/
pop_importev2.m
75 lines (66 loc) · 2.4 KB
/
pop_importev2.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
64
65
66
67
68
69
70
71
72
73
74
75
% pop_importev2() - merge a neuroscan EV2 file with input dataset
% (pop out window if no arguments).
%
% Usage:
% >> OUTEEG = pop_importev2( INEEG ); % pop-up window mode
% >> OUTEEG = pop_importev2( INEEG, filename);
%
% Inputs:
% INEEG - input EEGLAB data structure
% filename - file name
%
% Outputs:
% OUTEEG - EEGLAB data structure
%
% Author: Arnaud Delorme, SCCN, INC, UCSD, 2007
% Copyright (C) 2007 Arnaud Delorme, Salk Institute, [email protected]
%
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 2 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program; if not, write to the Free Software
% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
function [EEG, command] = pop_importev2(EEG, filename);
command = '';
if nargin < 1
help pop_importev2;
return;
end;
if nargin < 2
% ask user
[filename, filepath] = uigetfile('*.*', 'Choose a EV2 file -- pop_importev2');
drawnow;
if filename == 0 return; end
filename = fullfile(filepath, filename);
end
% find out if there is a line to skip or not
% ------------------------------------------
fid = fopen(filename, 'r');
tmpl = fgetl(fid);
if isempty(findstr('ype', tmpl)), skipline = 0;
else skipline = 1;
end
fclose(fid);
% load datas
% ----------
tmpevent = EEG.event;
try, oldeventlats = [ tmpevent.latency ]; catch, end
EEG = pop_importevent(EEG, 'fields', { 'num' 'type' 'response' 'acc' 'RT' 'latency'}, ...
'skipline', skipline, 'timeunit', 1E-3, 'align', NaN, 'append', 'no', 'event', filename );
tmpevent = EEG.event;
neweventlats = [ tmpevent.latency ];
if ~exist('oldeventlats'), oldeventlats = neweventlats; end
len = min(min(length(oldeventlats), length(neweventlats)), 10);
if mean(oldeventlats(1:len) - neweventlats(1:len)) > 1
error('Wrong alignment of ev2 file with data');
end
command = sprintf('EEG = pop_importev2(EEG, %s);', filename);
return;