Code covered by the BSD License  

Highlights from
Default arguments

Be the first to rate this file! 7 Downloads (last 30 days) File Size: 1.24 KB File ID: #41497
image thumbnail

Default arguments

by

 

25 Apr 2013 (Updated )

Set default values for optional function input.

| Watch this File

File Information
Description

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.

MATLAB release MATLAB 8.1 (R2013a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (1)
26 Apr 2013 Jan Simon

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
end
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.

Updates
26 Apr 2013

optimized code

26 Apr 2013

Optimized code

Contact us