You can use varargin in a function definition to specify that the function accepts a variable number of input arguments for a given input argument. You can use varargout in a function definition to specify that the function returns a variable number of arguments for a given output argument.
When you use varargin and varargout for code generation, there are the following limitations:
You cannot use varargout in the function definition for a top-level function.
You cannot use varargin in the function definition for a top-level function in a MATLAB Function block in a Simulink® model, or in a MATLAB® function in a Stateflow® diagram.
If you use varargin to define an argument to a top-level function, the code generation software generates the function with a fixed number of arguments. This fixed number of arguments is based on the number of example arguments that you provide on the command line or in a MATLAB Coder™ project test file.
Common applications of varargin and varargout for code generation are to:
Code generation relies on loop unrolling to produce simple and efficient code for varargin and varargout. This technique permits most common uses of varargin and varargout, but some uses are not allowed (see Variable Length Argument Lists for Code Generation).
For more information about using varargin and varargout in MATLAB functions, see Passing Variable Numbers of Arguments.