You can usually use vararginthese kinds of things to handle, but since you need nargin(g)to return the actual number of inputs, this is a bit more complicated.
You can use str2functo create an anonymous function as a string, and then convert it to a function descriptor.
% Create a list or arguments: x1, x2, x3, x4, ...
args = sprintf('x%d,', 1:nargin(func));
args(end) = '';
% Place these arguments into a string which indicates the function call
str = sprintf('@(%s)fun(someCalculationsWithSameSizeOfOutput(%s))', args, args);
% Now create an anonymous function from this string
g = str2func(str);
Based on the above value, it might be worth considering an alternative way to work with your functions.