Skip to content
Snippets Groups Projects
Commit f6b1da4b authored by William Lövfors's avatar William Lövfors
Browse files

small updates

parent 9356a89b
No related branches found
No related tags found
No related merge requests found
function [path,dirStruct] = FindBestParametersFile(pathToSearch) function [path,dirStruct] = FindBestParametersFile(pathToSearch, useSub, key)
%FINDBESTPARAMETERSFILE finds the file containing the best parameter set %FINDBESTPARAMETERSFILE finds the file containing the best parameter set
%based on the name. Assumes that the cost is given in parenthesis. %based on the name. Assumes that the cost is given in parenthesis.
% [path,name] = FindBestParametersFile(path) % [path,name] = FindBestParametersFile(path)
if nargin<3, key='.'; end
if nargin<2, useSub=0; end
%% %%
assert(exist(pathToSearch,'dir')>0,'Path does not exist. Are you in the right directory?'); assert(exist(pathToSearch,'dir')>0,'Path does not exist. Are you in the right directory?');
if useSub
pathToSearch=[pathToSearch '/**/*.mat'];
end
files=dir(pathToSearch); files=dir(pathToSearch);
assert(length(files)>2,'No files to search in the provided path') assert(length(files)>2,'No files to search in the provided path')
names=string({files.name});
files(cellfun(@isempty,regexp(names, key)))=[]; %removes all files not containing "key"
names=string({files.name}); names=string({files.name});
values=double(regexprep(names,{'.*\(','\).*'},{'',''})); 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)'); assert(any(~isnan(values)),'No files contains valid names. Make sure the files has the cost in parenthesis, e.g opt(12.34)');
......
No preview for this file type
function [] = SaveFile(fileName,variable, variableName) function [] = SaveFile(fileName,variable, variableName)
%SAVEFILE Saves a file with "fileName" with the content of a "variable" with %SaveFile, used to save file (works with parfor)
%SaveFile(fileName,variable, variableName)
%Saves a file with "fileName" with the content of a "variable" with
%name "variableName" %name "variableName"
S.(variableName)=variable; S.(variableName)=variable;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment