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

updated structfieldcat to handle 1D arrays, and FindBestParametersFile to...

updated structfieldcat to handle 1D arrays, and FindBestParametersFile to handle one given parameter file
parent 16d7b014
No related branches found
No related tags found
No related merge requests found
...@@ -13,15 +13,20 @@ end ...@@ -13,15 +13,20 @@ end
files=dir(pathToSearch); files=dir(pathToSearch);
assert(length(files)>0,'No files to search in the provided path') assert(length(files)>0,'No files to search in the provided path')
names=string({files.name}); names=string({files.name});
files(cellfun(@isempty,regexp(names, key)))=[]; %removes all files not containing "key" if length(files)>1
files(cellfun(@isempty,regexp(names, key)))=[]; %removes all files not containing "key"
names=string({files.name});
values=double(regexprep(names,{'.*\(','\).*'},{'',''})); names=string({files.name});
assert(any(~isnan(values)),'No files contains valid names. Make sure the files has the cost in parenthesis, e.g opt(12.34)'); values=double(regexprep(names,{'.*\(','\).*'},{'',''}));
[~,bestInd]=min(values); assert(any(~isnan(values)),'No files contains valid names. Make sure the files has the cost in parenthesis, e.g opt(12.34)');
name=files(bestInd).name; [~,bestInd]=min(values);
path=[files(bestInd).folder '/' name]; name=files(bestInd).name;
dirStruct=files(bestInd); 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 end
...@@ -6,7 +6,12 @@ for i=1:size(T,2) ...@@ -6,7 +6,12 @@ for i=1:size(T,2)
fields = fieldnames(S); fields = fieldnames(S);
for k = 1:numel(fields) for k = 1:numel(fields)
aField = fields{k}; % EDIT: changed to {} aField = fields{k}; % EDIT: changed to {}
if size(S.(aField),1) ==1 && size(S.(aField),2)>1 % If field is a horizontal 1D array
S.(aField) = cat(dim, S.(aField), T(i).(aField)); 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
end end
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment