It looks like you have a main function, and from this function you want to call a function LogParamsto get a list of variable names passed to the main function. Here is one way to implement your function LogParams:
function names = LogParams
names = evalin('caller','arrayfun(@inputname,1:nargin,''UniformOutput'',0)');
end
The result returned from LogParamswill be an array of cells containing the names of the variables passed to the calling function LogParams. The above solution uses the following functions:
- EVALIN : evaluate the expression in the workspace of the calling function.
- ARRAYFUN : as an alternative to the for loop.
- NARGIN : get the number of arguments passed to the function.
- INPUTNAME : get the name of the input variable.
To illustrate how it works LogParams, create the following function that calls it:
function main_function(a,b,varargin)
disp(LogParams);
end
( x, y z):
>> main_function(x,y)
'x' 'y'
>> main_function(x,y,z)
'x' 'y' 'z'
>> main_function(x,y,z,z,z,z)
'x' 'y' 'z' 'z' 'z' 'z'