-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwriteXLSMeanAnalysesGroups.m
168 lines (138 loc) · 7.89 KB
/
writeXLSMeanAnalysesGroups.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
function writeXLSMeanAnalysesGroups(bbstruct,bbmeta,user)
%writeXLSMeanAnalysesGroups: write analyses data to Excel in long form
% Prasanna Sritharan, April 2018
%
% Currently only implemented for joint rotational impulse
%
% --------------------------------------------------------------------
% Copyright (C) 2018 Prasanna Sritharan
% Copyright (C) 2018 La Trobe University
%
% 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 3 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, see <http://www.gnu.org/licenses/>.
% --------------------------------------------------------------------
warning('off');
% assign struct fields
subjprefix = user.SUBJECTPREFIX;
trialprefix = user.TRIALPREFIX;
xlspath = user.SUMMARYPATH;
taskshort = user.TASKSHORT;
samp = user.SAMP;
% summary data types
SDATA = {'mean','sd'};
SNAME = {'Mean','Stdev'};
% prepare output cell array
subjs = fieldnames(bbstruct);
for b=1:length(bbmeta.BBANALYSES)
bbanalysis = upper(bbmeta.BBANALYSES{b});
% skip if not RotImpulse or RotWork
% (note: only RotImpulse and RotWork required at this time, will
% add others as required)
if all(~strcmpi(bbanalysis,{'ROTIMPULSE','ROTWORK'})), continue; end;
% extract data
for f=1:3
cond = bbmeta.conditions{f};
for q=1:length(bbmeta.(bbanalysis))
quantlabel = bbmeta.(bbanalysis){q};
% determine number of columns
dcols = 1;
for c=1:3
for s=1:length(subjs)
if isfield(bbstruct.(subjs{s}),'mean')
if isfield(bbstruct.(subjs{s}).mean,cond)
if (~strcmpi(subjs{s},'MEAN'))&&(bbstruct.(subjs{s}).kinematicsonly)&&(~strcmpi(bbanalysis,'ANGLEEVENTVALS')), continue; end
dlen = length(bbstruct.(subjs{s}).mean.(cond).(bbanalysis).(quantlabel).segments.(bbmeta.dirs{c}));
if dlen>dcols, dcols=dlen; end
end
end
end
end
% sheet header row (means)
xldata.(cond).(bbanalysis).(quantlabel)(1,:) = ['Type','Subject','Quantity','Direction','Values',num2cell(NaN(1,dcols-1))];
% write data to long form table, padding columns where necessary
x = 2;
for m=1:2
sdtype = SDATA{m};
sdname = SNAME{m};
for s=1:length(subjs)
if isfield(bbstruct.(subjs{s}),sdtype)
if isfield(bbstruct.(subjs{s}).(sdtype),cond)
% skip kinetics if kinematics only
if (~strcmpi(subjs{s},'MEAN'))&&(bbstruct.(subjs{s}).kinematicsonly)&&(~strcmpi(bbanalysis,'ANGLEEVENTVALS')), continue; end
% allocate
dcellvec = cell(15,4+dcols);
% net
r = 1;
for c=1:3
dval = [bbstruct.(subjs{s}).(sdtype).(cond).(bbanalysis).(quantlabel).net(c), NaN(1,dcols-1)];
dcellvec(r,:) = [sdname,subjs{s},'net',bbmeta.dirs{c},num2cell(dval)];
r = r + 1;
end
% positive
for c=1:3
dval = [bbstruct.(subjs{s}).(sdtype).(cond).(bbanalysis).(quantlabel).positive(c), NaN(1,dcols-1)];
dcellvec(r,:) = [sdname,subjs{s},'positive',bbmeta.dirs{c},num2cell(dval)];
r = r + 1;
end
% negative
for c=1:3
dval = [bbstruct.(subjs{s}).(sdtype).(cond).(bbanalysis).(quantlabel).negative(c), NaN(1,dcols-1)];
dcellvec(r,:) = [sdname,subjs{s},'negative',bbmeta.dirs{c},num2cell(dval)];
r = r + 1;
end
% half
for c=1:3
dval = [bbstruct.(subjs{s}).(sdtype).(cond).(bbanalysis).(quantlabel).half(:,c)', NaN(1,dcols-2)];
dcellvec(r,:) = [sdname,subjs{s},'half',bbmeta.dirs{c},num2cell(dval)];
r = r + 1;
end
% segments
for c=1:3
dval = bbstruct.(subjs{s}).(sdtype).(cond).(bbanalysis).(quantlabel).segments.(bbmeta.dirs{c});
if isempty(dval), dval = 0; end;
dlen = length(dval);
dval = [dval, NaN(1,dcols-dlen)];
dcellvec(r,:) = [sdname,subjs{s},'segments',bbmeta.dirs{c},num2cell(dval)];
r = r + 1;
end
% append table to sheet
xldata.(cond).(bbanalysis).(quantlabel)(x:x+14,:) = dcellvec;
x = x + 15;
end
end
end
end
end
end
end
% write Excel spreadsheet
mkdir(xlspath);
mkdir([xlspath '\XLS\']);
for f=1:3
cond = bbmeta.conditions{f};
if isfield(xldata,cond)
for b=1:length(bbmeta.BBANALYSES)
bbanalysis = upper(bbmeta.BBANALYSES{b});
if all(~strcmpi(bbanalysis,{'ROTIMPULSE','ROTWORK'})), continue; end % skip if not RotImpulse or RotWork
s = 1;
xlsname = [upper(subjprefix) '_' upper(trialprefix) '_' upper(taskshort) '_' cond '_' bbanalysis '.xlsx'];
for q=1:length(bbmeta.(bbanalysis))
quantlabel = bbmeta.(bbanalysis){q};
sheetname = [quantlabel '_' bbmeta.units.(bbanalysis)];
writecell(xldata.(cond).(bbanalysis).(quantlabel),[xlspath '\XLS\' xlsname],'FileType','spreadsheet','Sheet',sheetname);
s = s + 1;
end
end
end
end
end