Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
5.5.2 - English

Change language to:
Français - 日本語 - Português - Русский

Please note that the recommended version of Scilab is 2024.0.0. This page might be outdated.
See the recommended documentation of this function

Scilab Help >> Advanced functions > varargin

varargin

variable number of arguments in an input argument list

Description

A function whose last input argument is varargin can be called with more input arguments than indicated in the input argument list. The calling arguments passed form varargin keyword onwards may then be retrieved within the function in a list named varargin.

Suppose that varargin keyword is the n-th argument of the formal input argument list, then if the function is called with less than n-1 input arguments the varargin list is not defined, if the function is called with n-1 arguments then varargin list is an empty list.

function y = ex(varargin) may be called with any number of input arguments. Within function ex input arguments may be retrieved in varargin(i), i=1:length(varargin).

If it is not the last input argument of a function, varargin is a normal input argument name with no special meaning.

The total number of actual input arguments is given by argn(2).

Remark

Named argument syntax like foo(...,key=value) is incompatible with the use of varargin. The reason is that the names (i.e. keys) associated with values are not stored in the varargin list. Consider for instance:

function foo(varargin)
    disp([varargin(1),varargin(2)])
endfunction
            -->foo(a=1,b=2)
            
            1.    2.
            
            -->foo(b=1,a=2)
            
            1.    2.
        

Result is the same, but the arguments were inverted.

Examples

function exampl(a, varargin)
    [lhs,rhs]=argn(0)
    if rhs>=1 then
        disp(varargin)
    end
endfunction

exampl(1)
exampl()
exampl(1,2,3)
l=list('a',%s,%t);
exampl(1,l(2:3))

See Also

  • argn — Returns the number of input/output arguments in a function call
  • function — opens a function definition
  • list — a Scilab object and a list definition function
  • varargout — variable numbers of arguments in an output argument list
Report an issue
<< tree2code Advanced functions varargout >>

Copyright (c) 2022-2023 (Dassault Systèmes)
Copyright (c) 2017-2022 (ESI Group)
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Wed Apr 01 10:14:07 CEST 2015