-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsave_mat_summaries.m
198 lines (175 loc) · 10.1 KB
/
save_mat_summaries.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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
%-------------------------------------------------------------------------%
% Copyright (c) 2020 Modenese L. %
% %
% Licensed under the Apache License, Version 2.0 (the "License"); %
% you may not use this file except in compliance with the License. %
% You may obtain a copy of the License at %
% http://www.apache.org/licenses/LICENSE-2.0. %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or %
% implied. See the License for the specific language governing %
% permissions and limitations under the License. %
% %
% Author: Luca Modenese, 2020 %
% email: [email protected] %
% ----------------------------------------------------------------------- %
% utility function to convert the simulation results in just two summary
% files to use with higher level functions to plot results and perform
% statistical analyses.
% ----------------------------------------------------------------------- %
function save_mat_summaries()
clear;clc;
fclose all;close all;
%---------------------------------------------------------------------------
% where the simulations are
database_root_folder = '.\Dataset';
% name of the models used in the simulations
model_set = {'P3m6_R_manual', 'P3m6_R_automatic'};
% where to store the summary
mat_summary_folder = './Dataset_Mat_Summaries';
% mass of the subject represented by the automatic and manual model
bodyMass = 76.5; %kg
%---------------------------------------------------------------------------
% create summary folder
if ~isfolder(mat_summary_folder); mkdir(mat_summary_folder); end
% initializations of all storage variables
pelvis_tilt= []; pelvis_list = []; pelvis_rotation = [];
hip_flexion = []; hip_flexion_moment = [];hip_adduction = []; hip_adduction_moment = [];
hip_rotation = []; hip_rotation_moment = []; knee_angle = []; knee_angle_moment = [];
ankle_angle = []; ankle_angle_moment = []; subtalar_angle = []; subtalar_angle_moment = [];
KINEMATICS = []; KINETICS = []; ToeOffV_R = [];
% getting data from simulations of each model
for n_subj = 1:length(model_set)
% extract details for the current model
cur_model_name = model_set{n_subj};
display(['Processing: ', cur_model_name])
% summary folders in model folder structure
Mat_summary_folder = fullfile(database_root_folder,cur_model_name,'Mat_summary');
% summary file
summary_file = fullfile(Mat_summary_folder, [cur_model_name,'_OS_allTrials.mat'] );
% load and remove external structure layer
subj_OS_summary = load(summary_file);
eval(['subj_OS_summary = subj_OS_summary.',cur_model_name,'_OS_summary;'])
if ~isempty(subj_OS_summary)
% PULLING TOE OFF
ToeOffV_R = [ToeOffV_R, subj_OS_summary.toe_off_vec]; %#ok<AGROW>
% STORING ALL KINEMATICS TOGETHER (with correct signs for plotting)
pelvis_tilt = -squeeze(getValueColumnForHeader(subj_OS_summary, 'pelvis_tilt'));
pelvis_list = -squeeze(getValueColumnForHeader(subj_OS_summary, 'pelvis_list'));
pelvis_rotation= squeeze(getValueColumnForHeader(subj_OS_summary, 'pelvis_rotation'));
hip_flexion = squeeze(getValueColumnForHeader(subj_OS_summary, 'hip_flexion_r'));
hip_adduction = squeeze(getValueColumnForHeader(subj_OS_summary, 'hip_adduction_r'));
hip_rotation = squeeze(getValueColumnForHeader(subj_OS_summary, 'hip_rotation_r'));
knee_angle =-(squeeze(getValueColumnForHeader(subj_OS_summary, 'knee_angle_r')));
ankle_angle = squeeze(getValueColumnForHeader(subj_OS_summary, 'ankle_angle_r'));
subtalar_angle = squeeze(getValueColumnForHeader(subj_OS_summary, 'subtalar_angle_r'));
% STORING ALL DYNAMICS TOGETHER (with correct signs for plotting)
hip_flexion_moment = -squeeze(getValueColumnForHeader(subj_OS_summary, 'hip_flexion_r_moment'))/bodyMass;
hip_adduction_moment = -squeeze(getValueColumnForHeader(subj_OS_summary, 'hip_adduction_r_moment'))/bodyMass;
hip_rotation_moment = squeeze(getValueColumnForHeader(subj_OS_summary, 'hip_rotation_r_moment'))/bodyMass;
knee_angle_moment = squeeze(getValueColumnForHeader(subj_OS_summary, 'knee_angle_r_moment'))/bodyMass;
ankle_angle_moment = -squeeze(getValueColumnForHeader(subj_OS_summary, 'ankle_angle_r_moment'))/bodyMass;
subtalar_angle_moment= -squeeze(getValueColumnForHeader(subj_OS_summary, 'subtalar_angle_r_moment'))/bodyMass;
end
%------------- create summary structures ------------------
% store kinematics
KINEMATICS.colheaders = {'pelvis_tilt', 'pelvis_list','pelvis_rotation',...
'hip_flexion','hip_adduction','hip_rotation',...
'knee_angle','ankle_angle','subtalar_angle'};
KINEMATICS.data = reshape([pelvis_tilt; pelvis_list; pelvis_rotation;...
hip_flexion; hip_adduction; hip_rotation;...
knee_angle; ankle_angle;subtalar_angle],...
101,length(KINEMATICS.colheaders),[]);
% store kinetics
KINETICS.colheaders = {'hip_flexion_moment','hip_adduction_moment',...
'hip_rotation_moment','knee_angle_moment',...
'ankle_angle_moment', 'subtalar_angle_moment'};
KINETICS.data = reshape([hip_flexion_moment; hip_adduction_moment;...
hip_rotation_moment; knee_angle_moment;...
ankle_angle_moment;subtalar_angle_moment],...
101,length(KINETICS.colheaders),[]);
% hyper-structure
SummaryBiomech.KINEMATICS = KINEMATICS;
SummaryBiomech.KINETICS = KINETICS;
SummaryBiomech.ToeOffV_R = ToeOffV_R;
% save the summary for this model
save([mat_summary_folder, filesep, ['Summary_',cur_model_name,'.mat']], 'SummaryBiomech')
disp(['Summary files written in folder: ',mat_summary_folder])
clear subj_OS_summary
end
end
%-------------------------------------------------------------------------%
% Copyright (c) 2020 Modenese L. %
% %
% Licensed under the Apache License, Version 2.0 (the "License"); %
% you may not use this file except in compliance with the License. %
% You may obtain a copy of the License at %
% http://www.apache.org/licenses/LICENSE-2.0. %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or %
% implied. See the License for the specific language governing %
% permissions and limitations under the License. %
% %
% Author: Luca Modenese, 2020 %
% email: [email protected] %
% ----------------------------------------------------------------------- %
% Function that allows to retrieve the value of a specified variable whose
% name is specified in var_name
%
% INPUTS
% struct: is a structure with fields 'colheaders', the headers, and 'data'
% that is a matrix of data.
% var_name: the name of the variable to extract
%
% OUTPUTS
% var_value: the column of the matrix correspondent to the header specified
% in input.
%
% modified 29/6/2016
% made changes to ensure that only one variable will be extracted.
% it also ensure extraction of 3D data by taking the 3rd dimension.
% includes modifications implemented in getValueColumnForHeader3D.m
% ----------------------------------------------------------------------- %
function var_value = getValueColumnForHeader(struct, var_name)%, varargin)
% bug scoperto da Giuliano 11/07/2017
if (iscell(var_name)) && isequal(length(var_name),1)
var_name = var_name{1};
elseif (iscell(var_name)) && length(var_name)>1
error('getValueColumnForHeader.m Input var_name is a cell array with more than one element. Not supported at the moment. Please give a single label.')
end
% initializing allows better control outside the function
var_value = [];
% gets the index of the desired variable name in the colheaders of the
% structure from where it will be extracted
var_index = strcmp(struct.colheaders, var_name);%june 2016: strcmp instead of strncmp ensures unique correspondance
if sum(var_index) == 0
% changed from error to warning so the output is the empty set
warning(['getValueColumnForHeader.m','. No header in structure is matching the name ''',var_name,'''.'])
else
% check that there is only one column with that label
if sum(var_index) >1
display(['getValueColumnForHeader.m',' WARNING: Multiple columns have been identified in summary with label ', var_name]);
pause
end
% my choice was to automatically extract the third dimension of a set
% using the 2D column headers indices
if ndims(struct.data)==3
var_value = struct.data(:,var_index,:);
else
var_value = struct.data(:,var_index);
end
% HERE IS AN ALTERNATIVE USING VARARGIN
% % maybe this could be better handled
% if isempty(varargin)
% var_value = struct.data(:,var_index);
% elseif strcmp(varargin{1},'3D')==1
% display('Extracting 3D data.')
% % uses the index to retrieve the column of values for that variable.
% var_value = struct.data(:,var_index,:);
% end
end
end