Skip to main content

orderByIndex.m


% This function is part of the NMSM Pipeline, see file for full license.
%
% Finds the first instance of a file with the given prefix in the given
% directory and returns the full file path.
%
% (string, string) -> (string)
% returns the full file name with the given prefix in the directory


function taskList = orderByIndex(tasks)
if length(tasks) == 1
taskList = tasks;
else
taskIndexValues = [];
for i=1:length(tasks)
try
taskIndexValues(end + 1) = str2double(tasks{i}.index.Text);
catch
throw(MException('', "<index> element not included for task"))
end
end
[~, sortedIndexArray] = sort(taskIndexValues);
taskList = {};
for i=1:length(sortedIndexArray)
taskList{end + 1} = tasks{sortedIndexArray(i)};
end
end
end