File Exchange

image thumbnail


version (1.96 KB) by Jared
Easy-to-use interface for parsing function inputs in the form of parameter-value pairs.

1 Download

Updated 15 Jan 2013

View Version History

View License

Easy-to-use interface for converting parameter-value pairs into variables within a function. Unlike inputParser and other typical parameter-value parsers, easyparse is able to (and by default does) directly create variables within the called function, rather than as fields of a struct.

- To create variables in the function workspace according to varargin consisting of parameter-value pairs, use this syntax in your function:

- To create only variables with allowed_names, create a cell array of allowed names and use this syntax:
easyparse(varargin, allowed_names);

- To create a struct with fields specified by the names in varargin, (similar to the output of inputParser) ask for an output argument:
s = easyparse(...);

As an example, let's say you wanted a function, epdemo, that took inputs 'blee', 'bloo', and 'blah'. Then epdemo would be called with in the typical parameter value manner:
epdemo('blee', 1:10, 'blah', 4, 'bloo', 0);

To parse these inputs within epdemo requires a single line:

function epdemo(varargin)

foo = blee*100;
bar = bloo - blah;

CAVEAT UTILITOR: this function relies on assignin statements. Input checking is performed to limit potential damage, but use at your own risk.

One of a series of simple functions to provide easier input parsing within MATLAB.

Cite As

Jared (2021). easyparse (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (9)


Hi Alan, thanks for the response and for pointing me in the direction of the procArgs function--I wasn't aware of it when I crated easyparse and easydefaults.

I think both solutions are very simple (especially since both easyparse and procArgs can take a single argument), but I might suggest that requiring procArgs to only populate existing variables in the function might be somewhat limiting.

One of the largest uses I have for easyparse--or parameter-value pairs in general--is for optional arguments: only if the caller defines a variable is that variable defined in the function. Optional arguments would seem to be difficult to achieve with procArgs. One could create artificial empty variables, but this might begin to get a little unwieldy, in my opinion.

Thanks again for the feedback!

Alan Robinson

Much easier than Matlab's inputparser. I do something similar with my procArgs function, except I get the list of allowed variables by requiring that they already be created in the calling function, which is arguably easier still.


Indeed, I was overthinking things again. easydefaults solved it, thanks :).


Hi Jurgen,

That seems very similar to what is done by standard function inputs. For instance, if you only send three parameters to:

function demo_function(a,b,c,d,e)

then only a,b,c will be defined, with d and e ignored. So unless I am misunderstanding, in the context of parsing inputs, I'm not sure what would be gained.

Or is there another, more general application for this functionality? If there's a compelling use case, what you're describing would be pretty easy to implement based on the code in easyparse.


Yes very similar to example 3 from deal(). However with deal() the number of outputs on the left must equal the number of inputs (i.e. length(C)). So if I give 10 output and only 5 input it gives an error. But I would like the first 5 to be assigned and the last 5 to be ignored.


Hi Jurgen, glad you like it!

Can you explain your use case a bit more? As far as I understand, standard function inputs do something pretty similar to what you're describing, but perhaps I don't understand what you are looking for. Like you said, so does deal (also check Example 3 in deal, namely: [a,b,c,d] = C{:}).

Or, if perhaps you're trying to establish default arguments, you could try easydefaults, here:


Very nice, is it also possible to pass only the values for varargin, and a cell list as second argument. So that every value in varargin get sequentially mapped to a name in the list?
Or maybe deal() can do that...


Hi Peter, I added an example function which calls easyparse to the description. Hope this helps!


can you put some examples, thanks

MATLAB Release Compatibility
Created with R2011b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!