Friday, July 17, 2015

Default function parameter setting in Matlab


if ~exist('param', 'var'),
    param = defaultParam;
end

Note that 'param' in the first line is in single quotes. It's a string, not the parameter itself.
This allows for reordering of parameters unlike the case of checking nargin.