forked from sccn/eeglab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstd_lm_seteegfields.m
170 lines (152 loc) · 5.55 KB
/
std_lm_seteegfields.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
% std_lm_seteegfields() - set limo fields in eeg sets
%
% Usage:
% >> EEG = std_lm_seteegfields(STUDY,EEG,index,'datatype','Channels','format', 'cell')
%
% Inputs:
% STUDY - studyset structure containing some or all files in EEG
% EEG - EEG dataset
% index - index of dataset in STUDY.datasetinfo
%
% Optional inputs:
% format - 'matrix' (default) or 'cell'
% datatype - 'channels' or 'components'
%
% Outputs:
% EEG - updated EEG structure
%
% See also:
%
% Authors: Cyril Pernet, The university of Edinburgh
% Arnaud Delorme, SCCN
% Ramon Martinez-Cancino, SCCN
% Copyright (C) 2015 Ramon Martinez-Cancino,INC, SCCN
%
% This file is part of EEGLAB, see http://www.eeglab.org
% for the documentation and details.
%
% Redistribution and use in source and binary forms, with or without
% modification, are permitted provided that the following conditions are met:
%
% 1. Redistributions of source code must retain the above copyright notice,
% this list of conditions and the following disclaimer.
%
% 2. Redistributions in binary form must reproduce the above copyright notice,
% this list of conditions and the following disclaimer in the documentation
% and/or other materials provided with the distribution.
%
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
% THE POSSIBILITY OF SUCH DAMAGE.
function EEG = std_lm_seteegfields(STUDY,EEG,index,varargin)
%% Settings defaults
% -----------------
try
options = varargin;
if ~isempty( varargin )
for i = 1:2:numel(options)
opt.(options{i}) = options{i+1};
end
else opt= []; end
catch
error('limo_create_single_trials() error: calling convention {''key'', value, ... } error');
end
try, opt.format; catch, opt.format = 'cell'; end
try, opt.datatype; catch, opt.datatype = 'channels'; end
% Getting measureflags
% --------------------
measures = {'erp','spec','ersp','timef','itc'};
% Getting prefix for channels/components
if strncmpi(opt.datatype,'chan',4)
prefix = 'dat';
elseif strncmpi(opt.datatype,'comp',4)
prefix = 'ica';
end
% Getting values
for i = 1:length(measures)
opt.(measures{i}) = STUDY.etc.measureflags.([prefix measures{i}]);
end
% ---
fields = fieldnames(opt);
c = 1;
for i = 1: length(structfun(@numel,opt))
if ~any ([isempty(eval(['opt.' fields{i}])),strcmp(fields(i),'format'), strcmp(fields(i),'datatype')])
in_options{c} = fields{i};
in_options{c+1} = eval(['opt.' fields{i}]);
c = c+2;
end
end
%% Loading datase
% --------------
path_tmp = rel2fullpath(STUDY.filepath,STUDY.datasetinfo(index).filepath);
name = fullfile(path_tmp, STUDY.datasetinfo(index).subject);
%% Channels: update EEG.set file
% -----------------------------
if strcmpi(opt.datatype,'channels')
prefix = 'dat';
else
prefix = 'ica';
end
% DATERP
if strcmp(opt.erp,'on')
ext = [ prefix 'erp' ];
EEG.etc.datafiles.(ext) = getfilename(name, [ '.' ext ]);
data = load('-mat',EEG.etc.datafiles.(ext));
EEG.etc.timeerp = data.times;
end
% DATSPEC
if strcmp(opt.spec,'on')
ext = [ prefix 'spec' ];
EEG.etc.datafiles.(ext) = getfilename(name, [ '.' ext ]);
data = load('-mat',EEG.etc.datafiles.(ext));
EEG.etc.freqspec = data.freqs;
end
% DAT TIMEF
if strcmp(opt.timef,'on')
ext = [ prefix 'timef' ];
EEG.etc.datafiles.(ext) = getfilename(name, [ '.' ext ]);
EEG.etc.datafiles.datersp = EEG.etc.datafiles.(ext);
data = load('-mat',EEG.etc.datafiles.(ext),'times','freqs');
EEG.etc.timeersp = data.times;
EEG.etc.freqersp = data.freqs;
end
% -------------------------------------------------------------------------
% -------------------------------------------------------------------------
function file_fullpath = rel2fullpath(studypath,filepath)
% Return full path if 'filepath' is a relative path. The output format will
% fit the one of 'filepath'. That means that if 'filepath' is a cell array,
% then the output will a cell array too, and the same if is a string.
nit = 1; if iscell(filepath), nit = length(filepath);end
for i = 1:nit
if iscell(filepath),pathtmp = filepath{i}; else pathtmp = filepath; end
if strfind(pathtmp(end),filesep), pathtmp = pathtmp(1:end-1); end % Getting rid of filesep at the end
if strfind(pathtmp(1:2),['.' filesep])
if iscell(filepath),
file_fullpath{i} = fullfile(studypath,pathtmp(3:end));
else
file_fullpath = fullfile(studypath,pathtmp(3:end));
end
else
if iscell(filepath),
file_fullpath{i} = pathtmp;
else
file_fullpath = pathtmp;
end
end
end
function name = getfilename(name, ext)
if ~exist([name ext],'file')
tmp = dir([name '*' ext ]);
name = fullfile(tmp(1).folder,tmp(1).name);
warning('couldn''t find a direct match between .set and .daterp\n loading %s',name)
else
name = [name ext];
end