I am trying to design a wrapper function that takes a function-handle as input as well as a Struct that contains the function's arguments and a reference struct, that contains the desired number of outputs for the function and the fiedldnames, that they should be stored under in a return struct. Something like this:
Is there any way to "resolve" the Struct-Fields of InputData and use them as input-arguments for funcHandle, when the number of fields/input arguments may vary?
Thank you!
function TestStruct = callFunctionUnderTest(funcHandle, InputData, OutputData)% InputData could be something like this:
% InputData.funcarg1
% InputData.funcarg2
% but with variable number of input arguments/fields!
% OutputData could be something like this:
% OutputData.output1
% OutputData.output2
% OutputData.output3
% but with variable number of outputs/fields!
TestStruct = [];% check if number of fields in OutputData is equivalent to returned outputs of function
if nargout(funcHandle) ~= length(fieldnames(OutputData)) errorend% function call
[TestStruct.(ouput1), TestStruct.(output2), TestStruct.(output3)] = funcHandle(InputData.funcarg1, InputData.funcarg2) end
Best Answer