Scilab Website | Contribute with GitLab | Scilab Community | ATOMS toolboxes
Scilab Online Help
2027.0.0 - 日本語


arguments

keyword to check function arguments. Arguments block must be the expression in the function.

Syntax

arguments
    argName1 (dimensions) datatype {validators} = defaultValue
    ...
    argNameN
end

Arguments

argName1, ... argNameN

Name of the arguments from function protoptype.

All input arguments must be declared in arguments block and in the same order.

(dimension)

Expected (i, j, ...) dimensions for an input argument like (2, 3, 4). Must be a list of integer values or : or input variable name.

Matrix form (4, [3 6 10]) can be used to except size of 4 x 3 or 4 x 6 or 4 x 10.

If input argument is a scalar and expected dimensions are bigger, input argument will be expand to match the expected dimensions.

If expected dimensions is a vector (1xn or nx1) and input argument is a vector, input will be transposed to match expected form.

datatype

Expected datatype of input arguments. Inputs must be of datatype or convertable to this type.

datatype can be double, (u)int(8/16/32/64), boolean, string.

It can also be the name of a classdef: the input must then be an object of this class or of a derived class, without conversion. As the class can be defined after the function, the name is checked at each call.

{validators}

Comma-separated list of predefined functions used to check input validity. Each validator must succeed for the input to be accepted.

Two equivalent syntaxes are accepted inside the braces:

  • Short form — only the validator name, the checked argument is implicit. Available for validators that take only the checked value as parameter (e.g. mustBeReal, mustBePositive, mustBeFinite, ...).

    x double {mustBeReal, mustBePositive}

  • Function-call form — the checked argument is passed explicitly. Required for validators that take additional parameters (e.g. mustBeGreaterThan, mustBeInRange, mustBeMember, mustBeA, ...). Also valid for single-argument validators.

    x double {mustBeGreaterThan(x, 0), mustBeLessThan(x, 10)}

Parameters of validators are inputs, constants, or values evaluated at each call: a field of an input (opts.max) and, in a classdef method, this, a property of the object (this.max) or a static property (MyClass.max).

x double {mustBeLessThan(x, this.max)}

List of validators

defaultValue

If an input is not given by caller, variable will take this value.

All variables with default value must be at the end of the prototype.

Examples

function test(x, y)
    arguments
        x (1, 10) double {mustBeReal, mustBePositive}
        y double = 1
    end

    disp(x, y)
end
//OK
a = 1:10;
test(a) //y == 1 its default value
test(a') //x will be transposed to match 1 x 10 dimensions, y == 1
test(42, 2) //x become a(ones(1, 10)) and y == 2
//rejected
test() //x is required
test(a, list(1)) // a list cannot be convert to a double
test(0:9) // x must be > 0

See also

History

バージョン記述
2024.0 Introduction in Scilab.
2027.0.0

classdef names as datatype. Validator parameters evaluated at each call: field of an input, this, property of the object or static property in classdef methods.

Report an issue
<< abort Control flow Arguments Validators >>

Copyright (c) 2022-2026 (Dassault Systèmes S.E.)
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:
Thu Oct 15 11:21:44 CEST 2026