Skip to main content

plotGcpGroundReactionsFromFiles.m


% This function is part of the NMSM Pipeline, see file for full license.
%
% Plot experimental and optimized ground reactions from Ground Contact
% Personalization results files. Moments are calculated about the midfoot
% superior marker projected down to the resting spring length.
%
% (string, string, double) -> (None)
% Plot experimental and modeled ground reactions.


function plotGcpGroundReactionsFromFiles( ...
experimentalGroundReactionsFileName, ...
optimizedGroundReactionsFileName, plotNumber)
% The optional plot number argument allows users to generate multiple plots
% without overwriting previous plots. By default, figure 1 is used.
if nargin < 3
plotNumber = 1;
end
titles = ["Anterior GRF" "Vertical GRF" "Lateral GRF" "X Moment" ...
"Y Moment" "Z Moment"];
import org.opensim.modeling.Storage
experimentalGroundReactions = ...
storageToDoubleMatrix(Storage(experimentalGroundReactionsFileName));
modeledGroundReactions = ...
storageToDoubleMatrix(Storage(optimizedGroundReactionsFileName));
time = findTimeColumn(Storage(experimentalGroundReactionsFileName));

figure(plotNumber)
for i = 1:6
subplot(2, 3, i);
experimental = experimentalGroundReactions(i, :);
model = modeledGroundReactions(i, :);
plot(time, experimental, "red", "LineWidth", 2)
hold on
plot(time, model, "blue", "LineWidth", 2)
error = rms(experimental - model);
title(titles(i) + newline + " RMSE: " + error)
xlabel('Time')
if i == 1
ylabel('Force (N)')
else if i == 4
ylabel('Moment (N*m)')
end
hold off
end
end