I run a lot of function on a series of files. so it's logical to make a function that runs my functions on files instead repeating the procedure in every file. The problem is number of arguments for every function is different! So the psudo-code is:
function [out1, out2]=batchDo(@func,adrs,arg1,arg2,...,argn)
files=ls(adrs);
for i=1:length(files)
raw=load([adrs files(i)]);
[out1, out2]=func(raw,arg1,arg2,...,argn)
out1s=out1+out1s;
out2s=out2+out2s;
end
out1=out1s/length(files);
out2=out2s/length(files);
Fortunately in my case outputs are almost similar and I can add a few dummies to make them all similar. But if there is anyway to address them similarly, I would be grateful.
Horchler answer is the right one, if I just pass the varargin as varargin{:} that automatically provides what I need. If you use the varargin in every function you have and then trying to address varargin.arg1 instead of arg1, it slows down your code. There are numerous articles that compare the performances.