Function With Variable Number of Input Arguments in MATLAB Last Updated : 28 Apr, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report MATLAB functions have the functionality that many other programming languages lack. A MATLAB function can take a variable number of input arguments, without the use of arrays or any additional functionality. The way to go about this in MATLAB is by using the varargin - which can be interpreted as VARiable ARGument INput. Now, the way to use varargin is in all lowercase and it must be passed as an input argument in the function declaration after all other input parameters. Syntaxfunction fun1 = fun(var1, var2, ..., varargin) ---function body--- end Varargin converts the input arguments to a cell array and thus, making it accessible within the scope of the function only. See the following examples to understand the same. Example 1In this example, we shall create a function that displays all the input arguments. Matlab % function function geeks(varargin) y=varargin; for i=1:length(y) disp(y(i)) end end We create a copy of the above varargin in the y variable and then, access it as an ordinary cell array. Output: Example 2In this example, we assign the output variables to the given input variables. The assignment depends on a number of output variables passed. Matlab % function function varargout = geeks(varargin) for i=1:nargout varargout{i} = varargin(i); end end In this function, we iterate through the length of output variables using the nargout keyword and assign each of the output variables, the respective input variable in sequence. Output: Comment More infoAdvertise with us Next Article How to Validate Number of Function Arguments in MATLAB? O owl0223 Follow Improve Article Tags : Software Engineering Technical Scripter 2022 MATLAB-Functions Similar Reads How to Validate Number of Function Arguments in MATLAB? MATLAB functions are generally defined input and output arguments. To validate the number of these input-output arguments, MATLAB provides us with the following functions: narginchknargoutchkSyntax:narginchk(<minimum-inputs>, <maximum-inputs>) nargoutchk(<minimum-outputs>, <maxi 3 min read How to Find Number of Function Arguments in MATLAB? The number of function arguments passed in MATLAB will be determined in the following article. Unlike C, C++, and Java, MATLAB can accommodate a variable amount of parameters provided into a function without throwing an error. We'll go through how we determine the actual amount of parameters supplie 4 min read Function Argument Validation in MATLAB The basics of Function Argument is, " The functions receive certain inputs from the calling command which applies in function syntax and processes it. sometimes It may or may not produce output argument it dependence completely on the functions efficiency or the accuracy of your code." Function Argu 5 min read Function with Multiple Inputs in a Script File in MATLAB MATLAB stands for Matrix Laboratory. It is a high-performance language that is used for technical computing. In this article, we will see a function with multiple inputs in a script file in MATLAB. Steps:The steps below can be used to build a function with multiple inputs in a MATLAB script file: L 2 min read Parse Function Inputs in MATLAB Basically, the parse function is a method that users use in the function to convert data from one format to another. In programming, parsing is the processing and analysis of strings of numbers. We can also say that the parse function is often used to convert strings to other data types such as numb 4 min read Function Arguments in Programming Function Arguments are values or variables passed into a function when it is called. The arguments to a function play a significant role as they provide the necessary input for the function to perform its intended task. In this article, we will discuss what are Function Arguments in Programming acro 3 min read Like