How to check whether an argument is supplied in function call?

I always do like that:

if ~exist('arg1','var')
  arg1=0;
end

As said by @Andrey, with this solution you can change the number/order of the arguments of the function, without changing the code. This is not the case with the nargin solution.

As said by @yuk, if you want to allow to skip arguments you can do:

if ~exist('arg1','var') || isempty(arg1)
  arg1=arg1DefaultValue;
end

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)