Skip to main content

getDataMatrix.m


% This function is part of the NMSM Pipeline, see file for full license.
%
% This function creates the A matrix containing the joint angles in
% the same order as the polynomial expression
%
% Inputs:
% polynomialExpressionMuscleTendonLength (1 x numberOfCoefficients)
% polyninomialExpressionMomentArms (degreesOfFreedom x numberOfCoefficients)
% jointAngles (numberFrames x degreesOfFreedom)
% theta (1 x degreesOfFreedom
%
% (Symbol array, 2D Symbol array, 2D Number matrix, Symbol array) ->
% (2D Number matrix)
%
% returns A matrix

% -----------------------------------------------------------------------

function matrix = getDataMatrix(polynomialExpressionMuscleTendonLength, ...
polyninomialExpressionMomentArms, jointAngles, theta)

% Populate symbolic theta(s) with actual data
for i = 1 : size(jointAngles, 2)
eval(['theta' num2str(i) ' = jointAngles(:,' num2str(i) ');']);
end
% Evaluate symbolic expressions for muscle tendon lengths and moment arms
for j = 1 : size(polyninomialExpressionMomentArms, 2)
muscleTendonLengthMatrix(:, j) = ...
eval(polynomialExpressionMuscleTendonLength(1, j)) .* ...
ones(size(jointAngles, 1), 1);
for k = 1 : size(jointAngles, 2)
momentArmsMatrix(:, k, j) = ...
eval(polyninomialExpressionMomentArms(k, j)) .* ...
ones(size(jointAngles, 1), 1);
end
end
% Create A matrix
matrix = [muscleTendonLengthMatrix; reshape(momentArmsMatrix, ...
[], size(polyninomialExpressionMomentArms, 2))];
end