From c902a2883201aa05d5b288a74ca0fcec05c52dea Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?William=20L=C3=B6vfors?= <william.lovfors@liu.se>
Date: Thu, 16 Jan 2020 11:44:05 +0100
Subject: [PATCH] Added FindBestParametersFile

---
 FindBestParametersFile.m | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
 create mode 100644 FindBestParametersFile.m

diff --git a/FindBestParametersFile.m b/FindBestParametersFile.m
new file mode 100644
index 0000000..8d10986
--- /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
+
-- 
GitLab