Parameter name-value pair parsing - concise syntax, no assignin, and very fast.
Updated 12 May 2016

Why do we need another parameter parsing solution? MATLAB's inputParser class, while flexible, is relatively slow. Simpler methods are verbose and/or only handle positional arguments. Many FEX parameter parsers use assignin, which is convenient, but also slow and unsafe.
This function combines brevity in usage, high performance, and the convenience and clarity of parameter name-value pairs. It is around 9-20x faster than inputParser, and is one of the fastest parameter parsers on FEX. For up-to-date documentation and bug reports, see GitHub.

parseParameters(Defaults, callerVarargin, varargin)

Optional inputs:
isCaseSensitive (bool): Default false. Determines case sensitivity
expandStruct (bool): Default true. If false, parseParameters returns a struct similar to the Defaults struct.

Within yourFunction(...), specify defaults in a struct:
Defaults.x = 1;
Defaults.y = 5;

Then call
[x,y] = parseParameters(Defaults,varargin);

The user can then call
to change x and y.
Note that it is case insensitive by default, and the user's order doesn't matter.

Cite As

Jeffrey Chiou (2024). parseParameters (, GitHub. Retrieved .

MATLAB Release Compatibility
Created with R2015a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Find more on Argument Definitions in Help Center and MATLAB Answers

Inspired by: loadOptions, ArgUtils

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Versions that use the GitHub default branch cannot be downloaded

Version Published Release Notes

Description and summary reformatting/updating.

To view or report issues in this GitHub add-on, visit the GitHub Repository.
To view or report issues in this GitHub add-on, visit the GitHub Repository.