"goal is not to write nice matlab code, but instead structure it in the most convenient way"   How come you believe there is conflict between "nice" and "convenient"? Whatever these words mean in this context.
Here is an "elegant" code that meets your original requirements. Example of use:
a = 1;
b = magic(3);
c = dir;
JustGetTheWorkDone a b c
prints
Name Size Bytes Class Attributes
a 1x1 8 double
b 3x3 72 double
c 89x1 57407 struct
varargin 1x3 342 cell
where
function JustGetTheWorkDone( varargin )
loadVarsFromBaseEnv( varargin{:} )
whos
end
and
function loadVarsFromBaseEnv( varargin )
try
for jj = 1 : length( varargin )
val = evalin( 'base', varargin{jj} );
assignin( 'caller', varargin{jj}, val )
end
catch
fprintf( 2, 'loadVarsFromBaseEnv: Something went wrong\n' )
end
end
Best Answer