Skip to main content

calcMinimumNormalizedFiberLengthDeviationCost.m


% This function is part of the NMSM Pipeline, see file for full license.
%
% (Array of number, struct) -> (Array of number)
% returns the cost for all rounds of the Muscle Tendon optimization


function cost = calcMinimumNormalizedFiberLengthDeviationCost( ...
modeledValues, experimentalData, costTerm)
errorCenter = valueOrAlternate(costTerm, "errorCenter", 0);
maximumAllowableError = valueOrAlternate(costTerm, "maxAllowableError", 0.3);
minNormalizedFiberLength = min(modeledValues.normalizedFiberLength, [], 3);
for i = 1 : size(experimentalData.muscleTendonLength,1)
for ii = 1 : length(experimentalData.muscleNames)
if minNormalizedFiberLength(i, ii) < experimentalData.minNormalizedMuscleFiberLength
minNormalizedFiberLengthError(i, ii) = ...
minNormalizedFiberLength(i, ii) - ...
experimentalData.minNormalizedMuscleFiberLength;
else
minNormalizedFiberLengthError(i, ii) = 0;
end
end
end

cost = calcDeviationCostArray(...
minNormalizedFiberLengthError, errorCenter, maximumAllowableError);
end