Unfortunately, there is no way to do this. You must explicitly pass empty values ββfor parameters that you do not want to pass, and you need to check this condition in your function to see if the parameter passed or not, and if it is empty or not. Something like that:
function fun(a, b, c, d, e, f, g) if nargin<3 error('too few parameters'); end if nargin<4 || isempty(d) d = default_value; end % and so on... end % call fun(a, b, c, [], [], g);
In the end, it may be easier to collect the optional parameters into one structure and check its fields:
function fun(a, b, c, opt) if nargin<3 error('too few parameters'); end if nargin>3 if ~isfield(opt, 'd') opt.d = default_value; end end end % call opt.g = g; fun(a, b, c, opt);
It is easier to call the function, and you do not need to specify empty parameters.
source share