diff --git a/FindBestParametersFile.m b/FindBestParametersFile.m new file mode 100644 index 0000000000000000000000000000000000000000..8d1098620062b8c3accdb8e48c65c193886ab856 --- /dev/null +++ b/FindBestParametersFile.m @@ -0,0 +1,18 @@ +function [path,dirStruct] = FindBestParametersFile(pathToSearch) +%FINDBESTPARAMETERSFILE finds the file containing the best parameter set +%based on the name. Assumes that the cost is given in parenthesis. +% [path,name] = FindBestParametersFile(path) +%% +assert(exist(pathToSearch,'dir')>0,'Path does not exist. Are you in the right directory?'); +files=dir(pathToSearch); +assert(length(files)>2,'No files to search in the provided path') +names=string({files.name}); +values=double(regexprep(names,{'.*\(','\).*'},{'',''})); +assert(any(~isnan(values)),'No files contains valid names. Make sure the files has the cost in parenthesis, e.g opt(12.34)'); +[~,bestInd]=min(values); +name=files(bestInd).name; +path=[files(bestInd).folder '\' name]; +dirStruct=files(bestInd); + +end +