-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmat2eeglab.m
83 lines (70 loc) · 1.95 KB
/
mat2eeglab.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
76
77
78
79
80
81
82
83
% Simple Function to save a matlab matrix as an EEGLAB file
%
% data : [channels , time, trials]
% time : vector with time in seconds (to specify baseline if needed)
% fsample : sampling rate
% setname : the name of your data set
%
% This function is provided as is. It only works for some specific type of
% data. This is a simple function to help the developer and by no mean
% an all purpose function.
%
% adapted from EEGLAB
%
% https://sccn.ucsd.edu/svn/software/eeglab/functions/miscfunc/fieldtrip2eeglab.m
%
% Leonardo Barbosa - [email protected]
% 24-10-2014
function [EEG] = mat2eeglab(data, time, fsample, setname)
[ALLEEG EEG] = eeglab;
% load chanlocs.mat
% EEG.chanlocs = chanlocs;
EEG.chanlocs = [];
nchan = size(data,1);
ntime = size(data,2);
ntrials = size(data,3);
for i=1:ntrials
EEG.data(:,:,i) = single(data(:,:,i));
end
EEG.setname = setname;
EEG.filename = '';
EEG.filepath = '';
EEG.subject = '';
EEG.group = '';
EEG.condition = '';
EEG.session = [];
EEG.comments = 'manually preprocessed in matlab';
EEG.nbchan = nchan;
EEG.pnts = ntime;
EEG.trials = ntrials;
EEG.srate = fsample;
EEG.xmin = time(1);
EEG.xmax = time(end);
EEG.times = time;
EEG.ref = []; %'common';
% try to export event information ?
EEG.event = [];
EEG.epoch = [];
% EEG.epoch(2)
% ans =
% event: [4 5 6]
% eventtype: {'DIN2' 'DIN2' ''}
% eventvalue: {'trigger' 'trigger' 'trial'}
% eventlatency: {[-4] [256] [952]}
% eventduration: {[0] [0] [1448]}
% EEG.event(1)
% ans =
% type: 'DIN2'
% value: 'trigger'
% latency: 62
% duration: 0
% epoch: 1
% urevent: 1
EEG.icawinv = [];
EEG.icasphere = [];
EEG.icaweights = [];
EEG.icaact = [];
EEG.saved = 'no';
[~, EEG] = eeg_store(ALLEEG, EEG);
% eeglab redraw
% pop_eegplot( EEG, 1, 1, 1);