The inputParser.addOptional method is being used for the optional arguments. addOptional is meant for positional arguments, i.e., arguments that are interpreted based on their position of the argument list. From mathworks documentation:
Arguments added to the input parser scheme with the addOptional function are positional. Therefore, add them to the input parser scheme in the same order they are passed into the function.
However, all examples show them being used as named parameters and out of order:
mdDelay(data, 'maxLag', 25, 'plottype', 'all');
I have tested it in Matlab and indeed it works. However, it is weird because not only the options are out of order (the options order is plottype, numBins, maxLag,...) but also because the option names seem to be ignored. Reading the documentation, one would expect that the above call would result in the following:
plottype = 'maxLag'
numBins = 25
maxLag = 'plottype'
criterion = 'all'
I don't understand how this is working in Matlab, but it would be clearer if addParameter was used instead:
Use addOptional to add an individual argument into the input parser scheme. If you want to parse an optional name-value pair, then use the addParameter function.
The reason to request this change is so that this code can also be used in Octave.
The
inputParser.addOptionalmethod is being used for the optional arguments.addOptionalis meant for positional arguments, i.e., arguments that are interpreted based on their position of the argument list. From mathworks documentation:However, all examples show them being used as named parameters and out of order:
I have tested it in Matlab and indeed it works. However, it is weird because not only the options are out of order (the options order is plottype, numBins, maxLag,...) but also because the option names seem to be ignored. Reading the documentation, one would expect that the above call would result in the following:
I don't understand how this is working in Matlab, but it would be clearer if
addParameterwas used instead:The reason to request this change is so that this code can also be used in Octave.