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 |