getopt
Usage:
opt = getopt( struct( '<opt>', <default>|'noarg' , '<opt>', <default>|'noarg', ... ), varargin{:} )
Or
[opt vararg] = getopt( struct( '<opt>', <default>|'noarg' , '<opt>', <default>|'noarg', ... ), varargin{:} )
where
varargin = {'<opt>', [<value>], '<opt>', [<value>], ... }
A pair '<opt>', <default> specifies an argument:
If '<opt>',<value> is found in varargin, opt.<opt> = <value>
Otherwise, opt.<opt> = <default>.
A pair '<opt>', 'noarg' specifies a flag:
If '<opt>' is found in varargin, opt.<opt> = 1.
Otherwise, opt.<opt> = 0.
Options and flags in varargin can appear in arbitrary order.
vararg returns a list of unmatched entries in varargin,
which is useful as arguments for a further level of function call.
EXAMPLE:
varargin = {'length',10, 'cube', 'density',13}; % typically assigned via a function call instead
opt = getopt(struct('length',0, 'width',0, 'height',0, 'density',1, 'cube','noarg' ), varargin{:});
It returns:
opt =
length: 10
width: 0
height: 0
density: 13
cube: 1
Cite As
Chi-Hang Lam (2026). getopt (https://www.mathworks.com/matlabcentral/fileexchange/69933-getopt), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxCategories
Tags
Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
| Version | Published | Release Notes | |
|---|---|---|---|
| 1.0.0 |
