Due to legacy function calls I'm sometimes forced to write ugly wrappers like this
function return = someWrapper(someField)
a = someField.a;
b = someField.b;
% and so on, realistically it's more like ten variables that
% could actually be grouped in a struct
save('params.mat', 'a', 'b'); %etc.
% then, on another machine, a function loads params.mat, does the calculations
% and saves the result in result.mat containing the variables c,d,...
load('result.mat', 'c', 'd');
return.c = c;
return.d = d;
% again, it's more than just two return values
So the basic idea is to create variables with the same names as someField
's fieldnames, run a function and create a return
structure using someFunction
's return variable's names as fieldnames.
Is there some way simplify this using some loop e.g. over fieldnames(someField)
?
Or should I actually use some different approach? Since some further processing is done with someField
and result
I'd like to keep using structs, but maybe a second question would be
Can save
and load
redirect varibale names? I.e. could e.g. the variable a
in params.mat be stored using someField.a
as value instead of having to assign a = someField.a
first?