Function With Variable Number of Input Arguments in MATLAB Last Updated : 28 Apr, 2025 Comments Improve Suggest changes 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 O owl0223 Follow 0 Improve O owl0223 Follow 0 Improve Article Tags : Software Engineering Technical Scripter 2022 MATLAB-Functions Explore Software Engineering BasicsIntroduction to Software Engineering7 min readSoftware Development Life Cycle (SDLC)8 min readSoftware Quality - Software Engineering5 min readISO/IEC 9126 in Software Engineering4 min readBoehm's Software Quality Model4 min readSoftware Crisis - Software Engineering3 min readSoftware Measurement & MetricesSoftware Measurement and Metrics4 min readPeople Metrics and Process Metrics in Software Engineering7 min readHalsteadâs Software Metrics - Software Engineering10 min readCyclomatic Complexity6 min readFunctional Point (FP) Analysis - Software Engineering8 min readLines of Code (LOC) in Software Engineering4 min readSoftware Development Models & Agile MethodsWaterfall Model - Software Engineering12 min readWhat is Spiral Model in Software Engineering?9 min readPrototyping Model - Software Engineering7 min readIncremental Process Model - Software Engineering6 min readRapid Application Development Model (RAD) - Software Engineering9 min readCoupling and Cohesion - Software Engineering10 min readAgile Software Development - Software Engineering15+ min readSRS & SPMSoftware Requirement Specification (SRS) Format5 min readSoftware Engineering | Quality Characteristics of a good SRS7 min readSoftware Project Management (SPM) - Software Engineering8 min readCOCOMO Model - Software Engineering15+ min readCapability Maturity Model (CMM) - Software Engineering10 min readIntegrating Risk Management in SDLC | Set 18 min readSoftware Maintenance - Software Engineering13 min readTesting & DebuggingWhat is Software Testing?11 min readTypes of Software Testing15+ min readTesting Guidelines - Software Engineering3 min readWhat is Debugging in Software Engineering?11 min readVerification & ValidationVerification and Validation in Software Engineering6 min readRole of Verification and Validation (V&V) in SDLC5 min readRequirements Validation Techniques - Software Engineering8 min readPractice QuestionsTop 50+ Software Engineering Interview Questions and Answers15+ min read Like