atutils#
Classes
Definition of default parameters |
Functions
Process positional arguments from the input arguments |
|
Handle positional dp arguments |
|
(NAME, DEFAULTVALUE) |
|
Check the presence of a flag in an argument list |
|
Extract a keyword argument from an argument list |
|
Check and expands optional argument lists |
|
Set AT preference values |
- class atoptions#
- Definition of default parametersSingleton class for the storage of AT default values
- getargs(argin, def1, def2, ...)#
- Process positional arguments from the input argumentsProcess input arguments (typically from VARARGIN), replacing missingarguments by default values. The default values is also used when anargument is “[]” (empty numeric array).[v1,v2,…,remargs]=getargs(argin,def1,def2,…)Return as many variables as default values, plus a cell array ofremaining arguments.[…]=getargs(argin,…,’check’,checkfun)Check each input arguments using checkfun(arg) and stops processingat the first failing argument. Remaining arguments are available inREMARGS. “checkfun” may either:- return “false”: the function continues using the default value,- throw an exception: the function aborts, control is returned tothe keyboard or an enclosing try/catch block. The default valueis never used but must be specified.Matlab R2020b introduces a series of function “mustBe*” that canbe used for checkfun.Example 1:[optflag,args]=getflag(varargin,’option’); % Extract an optional flag[range,args]=getoption(args,’Range’, 1:10); % Extract a keyword argument[dname,dvalue]=getargs(args,’abcd’,297); % Extract positional argumentsExample 2:global THERING[ring,args]=getargs(varargin,thering,’check’,@iscell)If the 1st argument is a cell array, it will be used as “ring”,otherwise, THERING will be used. In both cases, the remainingarguments are available in “args”.Example 3:function checkcell(arg)if ~iscell(A)throwAsCaller(MException(‘AT:WrongType’,’Argument must be a cell array’));end[ring,args]=getargs(varargin,{},’check’,@checkcell)If the 1st argument is a cell array, it will be used as “ring” and theremaining arguments are available in “args”. Otherwise, the functionaborts with an error message.See also
getflag()
,getoption()
- getdparg(varargs)#
- Handle positional dp arguments[dp,varargs]=getdparg(varargs)If the 1st argument in VARARGS is a scalar numeric less than 1, it isconsidered as DP and removed from VARARGS.varargs=getdparg(varargs)DP is extracted, and if it is finite and non-zero,{‘DP’, DP} is added to VARARGS
- getenvopt()#
- (NAME, DEFAULTVALUE)Looks for an environment variable and return a default value if absent
- getflag(args, optname)#
- Check the presence of a flag in an argument listoption=getflag(args,optname)Return a logical value indicating the presence of the flag name in theargument list. Flag names are case insensitive.ARGS: Argument list (cell array)OPTNAME: Name of the desired option (string)[option,newargs]=getflag(args,optname)Returns the argument list after removing the processed flagExample:function testfunc(varargin)[optflag,args]=getflag(varargin,’option’); % Extract an optional flag[range,args]=getoption(args,’Range’, 1:10); % Extract a keyword argument[width, height]=getargs(args, 210, 297); % Extract positional argumentsDee also GETOPTION, GETARGS
- getoption(args, 'key', default)#
- Extract a keyword argument from an argument listvalue=getoption(args,’key’,default)value=getoption(args,key=default) in Matlab >= R2021aExtract a keyword argument, in the form of a pair “key,value” frominput arguments ARGS (typically from VARARGIN).Return DEFAULT value if the keyword is absentARGS: Argument list: cell array (usually VARARGIN) or structureKEY: Key nameDEFAULT: Value used if “key,value” is absent from the argument listvalue=getoption(args,’key’)The default value is taken from a list of predefined keys. Usegetoption() for the list of predefined keysvalue=getoption(args,{‘key1’,’key2’,…)Value is the list of key/value pairs matching KEY1 or KEY2 or…value=getoption(‘key’)Return the default value of a predefined key. Use getoption() forthe list of predefined keysvalue=getoption()Return all the default values[value,remargs]=getoption(args,…)Return the remaining arguments after removing the processed onesExample:function testfunc(varargin)[flag,args] = getflag(varargin, ‘Flag’); % Extract an optional flag[range,args] = getoption(args, ‘range’, 1:10); % Extract a keyword argument[width, height] = getargs(args, 210, 297}); % Extract positional arguments
- parseargs(default_values, argin)#
- Check and expands optional argument listsargout=parseargs(default_values,argin)[arg1,arg2,…]=parseargs(default_values,argin)obsolete: see GETARGS
- setoption('key', default)#
- Set AT preference valuessetoption(‘key’,default)Set the default value for the given KEY to DEFAULT. It is an error to seta default for a non-existing KEY. Use GETOPTION() for the list ofpredefined keys.KEY: Key nameDEFAULT: New default value for the keysetoption(‘key’) Resets the default value for KEY to its inital settingsetoption() Resets all values to their initial settingSee also
getoption()
,atoptions