Stuart’s MATLAB Videos

Watch and Learn

Trying Out inputparser

Posted by Stuart McGarrity,

I’m going to try to use inputparser for the first time, to specify name-value pair parameters for my function.

Its been around for several years but I haven’t used it. Typically my functions are “old school” where parameters need to be in certain positions. I use varargin for optional additional parameters, followed by some logic to set default values should later parameters not be present.

Currently I have a function which already has a few parameters, and I want to add more. With positional parameters, you have to supply all the ones up to the one you need which can get cumbersome if there are many. So I thought I would try using inputparser and make some of the parameters name-value pairs. This will give more flexibility in allowing only certain parameters to be specified.

Features covered in this code-along style video include:

Follow me (@stuartmcgarrity) if you want to be notified via Twitter when I post.

Play the video in full screen mode for a better viewing experience.