forked from anne-urai/2022_Urai_choicehistory_MEG
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreproc_appendRecs.m
76 lines (57 loc) · 2.32 KB
/
preproc_appendRecs.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
function [] = preproc_appendRecs(sj, sessions)
% split up the files into reflocked, stimlocked, resplocked and fblocked
% apply ft_megrealign per trial to improve sensor level statistics?
clc; close all;
if ~isdeployed,
addpath('~/code/MEG');
addpath(genpath('~/code/Tools'));
addpath('~/Documents/fieldtrip');
ft_defaults; % ft_defaults should work in deployed app?
end
warning off;
% ==================================================================
% LOAD IN SUBJECT SPECIFICS AND READ DATA
% ==================================================================
% for running on stopos
if ischar(sj), sj = str2double(sj); end
subjectdata = subjectspecifics(sj);
if ~exist('sessions', 'var'), sessions = 1:length(subjectdata.session); end
if ischar(sessions), sessions = str2double(sessions); end
% ==================================================================
% TIMELOCK DATA
% ==================================================================
for session = sessions,
clearvars -except sj session sessions subjectdata;
inputfiles = {};
for rec = subjectdata.session(session).recsorder,
% load in this file
load(sprintf('%s/P%02d-S%d_rec%d_cleandata.mat', ...
subjectdata.preprocdir, sj, session, rec));
fprintf('loading %s/P%02d-S%d_rec%d_cleandata.mat \n', ...
subjectdata.preprocdir, sj, session, rec);
% append data files...
inputfiles{end+1} = data;
% ... and grad structs
if ~exist('gradstructs', 'var'),
gradstructs = data.grad;
else
gradstructs(end+1) = data.grad;
end
end
% append all together
data = ft_appenddata([], inputfiles{:});
% keep grad structure for planar gradient transformation
% right now, cheat by taking the one from first recording
data.grad_first = inputfiles{1}.grad;
data.grad_avg = ft_average_sens(gradstructs);
data.grad_all = gradstructs;
% use this for now
data.grad = data.grad_first;
data = rmfield(data, 'cfg');
savefast(sprintf('%s/P%02d-S%d_cleandata.mat', ...
subjectdata.preprocdir, sj, session), 'data');
fprintf('SAVED %s/P%02d-S%d_cleandata.mat \n', ...
subjectdata.preprocdir, sj, session);
end
fprintf('DONE P%02d \n', sj);
end