diff --git a/FindBestParametersFile.m b/FindBestParametersFile.m index 5e15d89eb69757faa36db9a9afcfca677c66d271..776635800e7444c8f99567d68a783b46aa83a35d 100644 --- a/FindBestParametersFile.m +++ b/FindBestParametersFile.m @@ -13,15 +13,20 @@ end files=dir(pathToSearch); assert(length(files)>0,'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}); -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); - +if length(files)>1 + files(cellfun(@isempty,regexp(names, key)))=[]; %removes all files not containing "key" + + 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); +else + assert(contains(names,key), "File does not contain provided key") + path =[files.folder '/' files.name]; + dirStruct=files; +end end diff --git a/StructFieldCat.m b/StructFieldCat.m index a2ba43e596b3ad1796d25b3b441b2140e36931c6..9657ebcb682f5f440dabc78741da6fddbd4f3436 100644 --- a/StructFieldCat.m +++ b/StructFieldCat.m @@ -6,7 +6,12 @@ for i=1:size(T,2) fields = fieldnames(S); for k = 1:numel(fields) aField = fields{k}; % EDIT: changed to {} - - S.(aField) = cat(dim, S.(aField), T(i).(aField)); + if size(S.(aField),1) ==1 && size(S.(aField),2)>1 % If field is a horizontal 1D array + S.(aField) = horzcat(S.(aField), T(i).(aField)); + elseif size(S.(aField),2) > 1 && size(S.(aField),1)>1 %if field is a vertical 1D array + S.(aField) = vertcat(S.(aField), T(i).(aField)); + else + S.(aField) = cat(dim, S.(aField), T(i).(aField)); + end end end \ No newline at end of file