% This function is part of the NMSM Pipeline, see file for full license.
%
% This function looks in the given directory for all subdirectories and
% finds a file that ends in Length.sto to load into the 3D number matrix
% matching (numFrames, numTrials, numMuscles)
%
% (string) -> (3D matrix of number)
% returns a 3D matrix of the loaded muscle tendon length data
function [cells, columnNames] = parseFileFromDirectories(directories, suffix, model)
import org.opensim.modeling.Storage
[firstTrial, columnNames] = parseFileInDirectory(directories(1), ...
suffix, model, true);
cells = zeros([length(directories) size(firstTrial)]);
cells(1, :, :) = firstTrial;
for i=2:length(directories)
cells(i, :, :) = parseFileInDirectory(directories(i), suffix, model, false);
end
end
function [data, columnNames] = parseFileInDirectory(inputDirectory, ...
suffix, model, findColumnNames)
import org.opensim.modeling.Storage
data = '';
files = findDirectoryFileNames(inputDirectory);
for i=1:length(files)
if(contains(files(i), suffix))
[~, ~, data] = parseMotToComponents(model, Storage(files(i)));
if(findColumnNames)
columnNames = getStorageColumnNames(Storage(files(i)));
findColumnNames = false;
end
break;
end
end
if(strcmp(data, ''))
throw(MException('',"Unable to find " + suffix + " data file in " + ...
"directory " + strrep(inputDirectory, '\', '\\') + ...
" with prefix matching the input directory"))
end
end