I'm wondering how to write a function in Matlab with two different ways of passing the same input.
One example of this is the built-in function lsqcurvefit
. You can either pass the input like this:
x = lsqcurvefit(fun,x0,xdata,ydata,lb,ub,options)
where the first 4 arguments are required and the last 3 are optional, OR you can call it like this:
x = lsqcurvefit(problem)
where problem
is a struct
containing the same inputs. In this case there is only one required input.
My question is: how do I write a function that can take the same input in two different ways?
I looked at documentation and can't seem to find it because I just don't know what words or terminology to search for... Can someone point me to this? I'm sure it's very simple. Maybe it's trivial and I'm just missing it?
Ben
EDIT: It seems what I may have been looking for is 'function overloading' and 'function signature'.