% This function is part of the NMSM Pipeline, see file for full license.
%
% This function takes the result struct and writes the values to the
% appropriate .osimx muscle model, .mot muscle moment, and .sto muscle
% activation files. The model is included in instances where the results
% are relative to the original model, which is used for reference.
%
% (Model, struct, string, string, string) -> (None)
% Saves results in the struct to the given filenames
function saveMuscleTendonPersonalizationResults(modelFileName, ...
osimxFileName, prefixes, coordinateNames, finalValues, results, ...
resultsDirectory, muscleColumnNames)
model = Model(modelFileName);
% muscleColumnNames = getEnabledMusclesInOrder(model);
if ~exist(resultsDirectory, "dir")
mkdir(resultsDirectory);
end
if ~exist(fullfile(resultsDirectory, "muscleActivations"), "dir")
mkdir(fullfile(resultsDirectory, "muscleActivations"));
end
if ~exist(fullfile(resultsDirectory, "modelMoments"), "dir")
mkdir(fullfile(resultsDirectory, "modelMoments"));
end
for i = 1:size(results.muscleActivations, 1)
% Need to figure out how to print out individuals file names for each trial
writeToSto(muscleColumnNames, results.time(i, :), ...
squeeze(results.muscleActivations(i, :, :))', fullfile(resultsDirectory, ...
"muscleActivations", strcat(prefixes(i), "_muscleActivations", ".sto")));
writeToSto(coordinateNames, results.time(i, :), ...
squeeze(results.muscleJointMoments(i, :, :))', fullfile(resultsDirectory, ...
"modelMoments", strcat(prefixes(i), "_modelMoments", ".sto")));
end
muscleNames = getMusclesFromCoordinates(model, coordinateNames);
writeMuscleTendonPersonalizationOsimxFile(modelFileName, osimxFileName, ...
finalValues, muscleNames, resultsDirectory);
end