matlab - Clever way to assign multiple fields at once? -
due legacy function calls i'm forced write ugly wrappers this
function return = somewrapper(somefield) = somefield.a; b = somefield.b; % , on, realistically it's more ten variables % grouped in struct save('params.mat', 'a', 'b'); %etc. % then, on machine, function loads params.mat, calculations % , saves result in result.mat containing variables c,d,... load('result.mat', 'c', 'd'); return.c = c; return.d = d; % again, it's more 2 return values so basic idea create variables same names somefield's fieldnames, run function , create return structure using somefunction's return variable's names fieldnames.
is there way simplify using loop e.g. on fieldnames(somefield)?
or should use different approach? since further processing done somefield , result i'd keep using structs, maybe second question be
can save , load redirect varibale names? i.e. e.g. variable a in params.mat stored using somefield.a value instead of having assign a = somefield.a first?
why not this?
if s:
s.a=1 s.b=2 s.c=3 then command creates matfile named "arguments" variables a, b, c:
save arguments.mat -struct s and command loads matfiles variables structure
r = load('arguments.mat')
Comments
Post a Comment