Code covered by the BSD License  

Highlights from
getvarargin

Be the first to rate this file! 1 Download (last 30 days) File Size: 2.5 KB File ID: #21449

getvarargin

by Ikaro Silva

 

16 Sep 2008 (Updated 16 Sep 2008)

Function to help populate its calling function with variable number of input arguments, default valu

| Watch this File

File Information
Description

Utility function that makes it easier to work with variable number of input arguments. GETVARARGIN allows:

*An optional logical check on the inputs (ie, check input type, range etc), issuing an error on the calling function if condition are not met.

*An easy way to assign default values

*Input variables can be '&' prefix before the variable name as string followed by the variable value

For example, a function that generates a tone using getvargin in the example attached can be called in any of these ways:

%sequential with respect to signature
tone(1000,1,[],[],'hanning');

%string-value pair
tone(1000,1,'&win','hanning');

%Using default window which is hanning
tone(1000,1);

Logical tests on input are optional,here tone uses a check to make sure the frequency is positive,a negative frequency will issue a specific error according to the logical test applied:

>> tone(-1000,1)
??? Error using ==> tone at 15
Input Error Using:
 [x,t]=tone(f,dur,Fs,fase,win,show)

Argument f is f<0

MATLAB release MATLAB 7.0.1 (R14SP1)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (2)
16 Sep 2008 Duane Hanselman

No H1 help line. Help does not help me figure out what this function actually does. I am lost; perhaps because I have been using MATLAB for 25 years now? How many input arguments are there and what do they do? How many output arguments are there and what do they do? (The m-file shows one output variable, but what does it do?)

17 Sep 2008 Jos x@y.z

It is much simpler and cleaner to assign default values and check for errors within a function itself. Rather than a crytpic error message, such as "Argument dur is dur<0" one is better off with a decent phrase like "Second argument should be larger than 0". (and what if the error trap is something more elaborate, involving more tests and more arguments ...).
Although the author has certainly tried to make this submission useful by providing help, examples etc., I would not recommend this to anyone.

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
development environment Ikaro Silva 22 Oct 2008 10:19:41
varargin Ikaro Silva 22 Oct 2008 10:19:41
nargin Ikaro Silva 22 Oct 2008 10:19:41
default values Ikaro Silva 22 Oct 2008 10:19:41
variable Ikaro Silva 22 Oct 2008 10:19:41
inputs Ikaro Silva 22 Oct 2008 10:19:41

Contact us at files@mathworks.com