There are several ways to go about this:
Use optional input arguments if a given parameter means the same regardless of context, but if in some scenarios, additional input is needed.
function out = myFun(first,second,third,fourth)
%# first is always needed
if nargin < 1 || isempty(first)
error('need nonempty first input')
end
%# second is optional
if nargin < 2 || isempty(second)
second = defaultValueForSecondWhichCanBeEmpty;
end
%# etc
You can call this function as out = myFun(1,[],2,3)
, i.e. pass an empty array for non-needed inputs.
If two inputs mean that the function is used one way, and three inputs mean that the function is used in another way (and even the inputs mean different things), use VARARGIN
function out = myFun(varargin)
%# if 2 inputs, it's scenario 1, with 3 it's scenario 2
switch nargin
case 2
firstParameter = varargin{1};
secondParameter = varargin{2};
scenario = 1;
case 3
firstParameter = varargin{1}; %# etc
otherwise
error('myFun is only defined for two or three inputs')
end
Finally, you can also have your inputs passed as parameterName/parameterValue pairs. See for example this question on how to handle such input.