You can use varargin
and varargout
to
write wrapper functions that accept up to 64 inputs and pass them
directly to another function.
The following example passes a variable number of inputs to different optimization functions, based on a specified input method:
%#codegen function answer = fcn(method,a,b,c) answer = optimize(method,a,b,c); function answer = optimize(method,varargin) if strcmp(method,'simple') answer = simple_optimization(varargin{:}); else answer = complex_optimization(varargin{:}); end ...
You can use {:}
to read all
elements of varargin
and pass them to another function.
You can mix variable and fixed numbers of arguments.
For more information, see Variable Length Argument Lists for Code Generation.