Skip to main content

plotGcpFootKinematicsFromFiles.m


% This function is part of the NMSM Pipeline, see file for full license.
%
% Plot experimental and optimized foot kinematics from Ground Contact
% Personalization results files.
%
% (string, string, double) -> (None)
% Plot experimental and optimized foot kinematics.


function plotGcpFootKinematicsFromFiles(experimentalKinematicsFileName, ...
optimizedKinematicsFileName, 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
coordinates = ["Toe Angle", "Y Rotation", "X Rotation", "Z Rotation", ...
"X Translation", "Y Translation", "Z Translation"];
import org.opensim.modeling.Storage
experimentalKinematics = ...
storageToDoubleMatrix(Storage(experimentalKinematicsFileName));
modeledKinematics = ...
storageToDoubleMatrix(Storage(optimizedKinematicsFileName));
time = findTimeColumn(Storage(experimentalKinematicsFileName));

figure(plotNumber)
for i = 1:7
subplot(2, 4, i)
% Rotational coordinate data are converted to degrees.
if i <= 4
experimental = rad2deg(experimentalKinematics(i, :));
model = rad2deg(modeledKinematics(i, :));
else
experimental = experimentalKinematics(i, :);
model = modeledKinematics(i, :);
end
plot(time, experimental, "red", "LineWidth", 2)
hold on
plot(time, model, "blue", "LineWidth", 2)
error = rms(experimental - model);
title(coordinates(i) + newline + " RMSE: " + error)
xlabel('Time')
if i == 1
ylabel('Angle (deg)')
elseif i == 5
ylabel('Translation (m)')
end
hold off
end
end