MATLAB: Different functions with different variables as input

call functiondifferent inputsfunctions as input

Hello Matlab Community,
I have a problem, when different functions have different input variables. Then functions I call want of course all input variables. But I don't want to code for every function a single code. Do you have any idea, how I can "bundle" or something similar the input variables to loop them through the whole code with all called functions?
function [R, H, J] = RS(@func,@func2,x,y,eta, S)
[H] = F1(func, x ,y, eta, S); % called function 1

[J] = F2(func2,x,y,eta, S); % called function 2

H_inv = inv(H);
R = (H_inv*J*H_inv);
R = sqrt(diag(R));
end
in the example, the input variables "x,y,eta, S" are only for the RS function needed, but every func and func2 I want to run, have different number of input variables and different input variables. I've tried this
f = @(theta,eps,L,K,B,LK,FK,D)func(theta,eps,L,K,B,LK,FK,D);
f2 = @(theta,eps,L,K,B,LK,FK,D,ti,gi)func2(theta,eps,L,K,B,LK,FK,D,ti,gi);
function [R, H, J] = RS(f,f2,x,y,eta, S)
[H] = F1(f, x ,y, eta, S); % called function 1
[J] = F2(f2,x,y,eta, S); % called function 2
H_inv = inv(H);
R = (H_inv*J*H_inv);
R = sqrt(diag(R));
end
but, that doesn't work. Thanks in advance.

Best Answer

I think you can do this by bundling up the arguments for each function in a cell array. It would look something like this (untested):
function [R, H, J] = RS(@func,@func2,args,arg2)
[H] = F1(func, args{:}); % called function 1
[J] = F2(func2, args2{:}); % called function 2
H_inv = inv(H);
R = (H_inv*J*H_inv);
R = sqrt(diag(R));
end
The call to this function would look something like:
[R, H, J] = RS(@func,@func2,{theta,eps,L,K,B,LK,FK,D},{theta,eps,L,K,B,LK,FK,D,ti,gi})