File Exchange

image thumbnail

Default arguments

version 1.6 (1.24 KB) by

Set default values for optional function input.



View License

Set default arguments for use in function, without having to code the switch-case blocks. Code is quite trivial, but it saves me some time coding.

Comments and Ratings (1)

Jan Simon

Jan Simon (view profile)

What do you expect as result of this line:
varargin = varargin{:};
I assume, it should be deleted to avoid errors.
The code can be simplified:
varargout = defaults;
n = min(numel(defaults), numel(varargin));
varargout(1:n) = varargin(1:n);
if nargin > n
% error instead of a warning
An error is much more reliable than a warning, which will be overseen when a mutli-million line program fils the command window with status messages.



Optimized code


optimized code

MATLAB Release
MATLAB 8.1 (R2013a)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video