0

I am surprised that I couldn't find anything that exactly answers my question about this.

I want to define a function in Matlab where I can either enter a parameter or not.

What I mean is i.e. in Python I can write:

def x(a=0, b=2, c=4):
   return

and can call it with either

x(b=2, c=4)   
x(1, 2, 3) 
x(a=2, c=4)     

I already saw the exists functionality but that only works for the last parameter to be optional.

Is there any way to do this in Matlab, where I can put in the parameters as I like?

MagikarpSama
  • 323
  • 1
  • 11
  • MATLAB doesn't support named arguments. You would have to use name/value pairs for this. Please see the linked duplicates for the many options available (I'm partial to using [`inputParser`](https://www.mathworks.com/help/matlab/ref/inputparser.html)). – gnovice Jun 24 '19 at 20:55
  • Related: https://stackoverflow.com/questions/39799333/nargin-vargin-exist-what-is-the-best-way-to-implement-optional-arguments-matl – beaker Jun 24 '19 at 20:58

0 Answers0