function(a, b, c, varargin)
opt.foo = true;
opt.bar = false;
opt.blah = [];
opt.choose = {'this', 'that', 'other'};
opt.select = {'#no', '#yes'};
opt = tb_optparse(opt, varargin);
Optional arguments to the function behave as follows:
'foo' | sets opt.foo <- true |
'nobar' | sets opt.foo <- false |
'blah', 3 | sets opt.blah <- 3 |
'blah', {x,y} | sets opt.blah <- {x,y} |
'that' | sets opt.choose <- 'that' |
'yes' | sets opt.select <- 2 (the second element) |
and can be given in any combination.
If neither of 'this', 'that' or 'other' are specified then opt.choose <- 'this'.
If neither of 'no' or 'yes' are specified then opt.select <- 1.
Note:
- that the enumerator names must be distinct from the field names.
- that only one value can be assigned to a field, if multiple values
are required they must be converted to a cell array.
The allowable options are specified by the names of the fields in the
structure opt. By default if an option is given that is not a field of
opt an error is declared.
Sometimes it is useful to collect the unassigned options and this can be
achieved using a second output argument
[opt,arglist] = tb_optparse(opt, varargin);
which is a cell array of all unassigned arguments in the order given in
varargin.
The return structure is automatically populated with fields: verbose and
debug. The following options are automatically parsed:
'verbose' | sets opt.verbose <- true |
'debug', N | sets opt.debug <- N |
'setopt', S | sets opt <- S |
'showopt' | displays opt and arglist |
© 1990-2011 Peter Corke.