I’m trying to write a generalised logging function for all the input parameters passed to a function in MATLAB. Is it possible to easily pass all the input parameters to another function without individually naming the parameters? In the logging function, I can of course use inputname(i) in a for loop to get the parameter names. I would prefer not to have to perform this logic in the main function. So, is there a way to do something like LogParams(allInputParams)?
I’m trying to write a generalised logging function for all the input parameters passed
Share
It sounds like you have a main function, and from that function you want to call a function
LogParamsto get a list of the names of the variables passed to the main function. Here’s one way you could implement your functionLogParams:The output returned from
LogParamswill be a cell array containing the names of the variables passed to the function that callsLogParams. The above solution uses the following functions:As an illustration of how
LogParamsworks, create the following function that calls it:and now call it with a number of inputs (assuming the variables
x,y, andzare defined in the workspace):