Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use of undocumented inputParser.addOptional behaviour #1

Open
carandraug opened this issue Aug 30, 2019 · 1 comment
Open

use of undocumented inputParser.addOptional behaviour #1

carandraug opened this issue Aug 30, 2019 · 1 comment

Comments

@carandraug
Copy link

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.

@danm0nster
Copy link
Owner

Thanks, @carandraug

I will look into this. From your description it seems that using addParameter instead would be the correct way of dealing with the arguments. I've probably been influenced by how arguments are handled in JavaScript and Python and not read the MATLAB documentation properly.

I've added this to my to-do list and will look into it ASAP.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants