-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathorganizeMain.m
More file actions
152 lines (123 loc) · 6.92 KB
/
Copy pathorganizeMain.m
File metadata and controls
152 lines (123 loc) · 6.92 KB
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
% Wrapper function for organizing the data
function dataOrganized_subjAve = organizeMain(savenameMAT, alldata_LUT, handles)
% BOOLEAN FLAGS (mainly for debugging)
skipByCondition = 0;
skipNormalize = 0;
skipAverageTrials = 0;
skipScalarAverages = 0;
skipComputeCheckUpMatrix = 0;
skipAverageSubjects = 0;
skipAverageSubjects_wTrials = 1;
if handles.organizedFromMAT == 0
% Preallocate Cells
dataOrganized = cell(length(handles.colorConditionCell),1);
% size e.g. 3 x 1 : (3,1) - Dark / Red / White
%% Organize by condition
% this part takes quite long time, other parts of this code are
% faster so you typically want to skip this one
matFileName = 'dataOrg_mat_1stPass.mat';
if skipByCondition == 0
dataOrganized = organize_byCondition(savenameMAT, alldata_LUT, handles);
disp([' saving "', matFileName, '"'])
save(fullfile(handles.path.organizeMatFiles, matFileName), 'dataOrganized')
else
if skipNormalize ~= 1
disp([' loading "', matFileName, '"'])
load(fullfile(handles.path.organizeMatFiles, matFileName))
else
% no need to load this if next step is loaded from MAT
% as well
end
end
%% Normalize to trial 1
matFileName = 'dataOrg_mat_normalized.mat';
if skipNormalize == 0
dataOrganized_norm = organize_normalizeToTrialOne(dataOrganized, handles);
disp([' saving "', matFileName, '"'])
whos
clear dataOrganized
whos
% save(fullfile(handles.path.organizeMatFiles,
% matFileName), 'dataOrganized_norm', '-v7.3') 2.9 GB
else
if skipAverageTrials ~= 1
disp([' loading "', matFileName, '"'])
% load(fullfile(handles.path.organizeMatFiles,
% matFileName)) 2.9 GB
else
% no need to load this if next step is loaded from MAT
% as well
end
end
%% Average the trials (3 trials, average of them)
% note that this function works as well with the non-normalized
% data so you can give the dataOrganized as input argument as well,
% or call this function twice with different input arguments if
% needed
matFileName = 'dataOrg_mat_trialsAveraged.mat';
if skipAverageTrials == 0
dataOrganized_trialAve = organize_averageTheTrials(dataOrganized_norm, handles);
disp([' saving "', matFileName, '"'])
% save(fullfile(handles.path.organizeMatFiles, matFileName), 'dataOrganized_trialAve')
whos
else
disp([' loading "', matFileName, '"'])
load(fullfile(handles.path.organizeMatFiles, matFileName))
end
%% Get scalar averages (to correspond to the old code)
matFileName = 'dataOrg_mat_scalarAveraged.mat';
if skipScalarAverages == 0
whos
data_organized_meanScalar = organize_averageForScalars(dataOrganized_norm, handles);
disp([' saving "', matFileName, '"'])
save(fullfile(handles.path.organizeMatFiles, matFileName), 'data_organized_meanScalar')
else
disp([' loading "', matFileName, '"'])
load(fullfile(handles.path.organizeMatFiles, matFileName))
end
%% Compute "check-up matrix" to compare the current code to the original code (R. Hamner)
% and the mean power spectra found in Excel sheet "LRCSummary_norm3.xls"
matFileName = 'dataOrg_mat_checkupMatrix.mat';
if skipComputeCheckUpMatrix == 0
dataOrganized_checkupMatrix = organize_checkupMatrix(data_organized_meanScalar, handles);
disp([' saving "', matFileName, '"'])
save(fullfile(handles.path.organizeMatFiles, matFileName), 'dataOrganized_checkupMatrix')
else
disp([' loading "', matFileName, '"'])
load(fullfile(handles.path.organizeMatFiles, matFileName))
end
%% Average the subjects (from averaged trials)
% note that this function works as well with the non-normalized
% data so you can give the dataOrganized as input argument as well,
% or call this function twice with different input arguments if
% needed
matFileName = 'dataOrg_mat_subjAveraged.mat';
if skipAverageSubjects == 0
whos
dataOrganized_subjAve = organize_averageTheSubjects(dataOrganized_trialAve, handles);
disp([' saving "', matFileName, '"'])
save(fullfile(handles.path.matFiles, matFileName), 'dataOrganized_subjAve') % this is rather small file so we save it to Cloud
else
disp([' loading "', matFileName, '"'])
load(fullfile(handles.path.matFiles, matFileName))
end
%% Average the subjects (from all the trials)
% note that this function works as well with the non-normalized
% data so you can give the dataOrganized as input argument as well,
% or call this function twice with different input arguments if
% needed
matFileName = 'dataOrg_mat_subjAveraged_wTrials.mat';
if skipAverageSubjects_wTrials == 0
% dataOrganized_subjAve_wTrials = organize_averageTheSubjects_wTrials(dataOrganized_norm, handles);
disp([' saving "', matFileName, '"'])
save(fullfile(handles.path.matFiles, matFileName), 'dataOrganized_subjAve_wTrials')
else
disp([' loading "', matFileName, '"'])
load(fullfile(handles.path.matFiles, matFileName))
end
else
% skip the time-consuming computations and load the results from a
% .MAT-file
disp(' Skipping the organizeMain -computations, and loading results from "dataOrg_mat_subjAveraged.mat"')
load(fullfile(handles.path.matFiles, 'dataOrg_mat_subjAveraged.mat'))
end