Skip to content

inputParser

miscellaneous · scripts/miscellaneous/inputParser.m

: p = inputParser ()

Create an object that validates and collects the arguments of a function.

Declare arguments with addRequired, addOptional, addParameter and addSwitch, then call parse with the caller’s arguments. The values are available in the struct p.Results; p.UsingDefaults lists the declared optional arguments that were not supplied and p.Unmatched collects unrecognised name/value pairs when KeepUnmatched is true.

The object is a handle: methods change it in place. Settable properties are CaseSensitive, FunctionName, KeepUnmatched, PartialMatching and StructExpand.