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

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

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

Scilab Help >> Advanced functions > function


opens a function definition


closes a function definition


function <lhs_arguments>=<function_name><rhs_arguments>



stands for the name of the function


stands for the input argument list. It may be

  • a comma separated sequence of variable names enclosed in parenthesis, like (x1,...,xm). Last variable name can be the key word varargin (see varargin)

  • the sequence () or nothing, if the function has no input argument.


stands for the output argument list. It may be

  • a comma separated sequence of variable names enclosed in brackets, like [y1,...,yn]. Last variable name can be the key word varargout (see varargout)

  • the sequence [], if the function has no output argument. In this case the syntax may also be: function <function_name><rhs_arguments>


stands for a set of Scilab instructions (statements). This syntax may be used to define function (see functions) inline or in a script file (see exec). For compatibility with old Scilab versions, functions defined in a script file containing only function definitions can be "loaded" into Scilab using the exec function.

The function <lhs_arguments>=<function_name><rhs_arguments> sequence cannot be split over several lines. This sequence can be followed by statements in the same line if a comma or a semicolon is added at its end.

Note that <function_name> must respect some syntax rules (see names).

Function definitions can be nested.


//inline definition (see function)
function [x, y]=myfct(a, b)


//an one line function definition
function y=sq(x),y=x^2,endfunction


//nested functions definition
function y=foo(x)
function y=sq(x), y=x^2,endfunction


// definition in a script file (see exec)
exec SCI/modules/elementary_functions/macros/asinh.sci;

See also

  • functions — Scilab procedures and Scilab objects
  • exec — script file execution
  • names — Naming rules for variables and functions


6.0.0 function and endfunction are now protected: Assignments like function=1 or endfunction=2 are no longer possible.
Report an issue
<< funcprot Advanced functions functions >>

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:
Tue Feb 25 08:49:22 CET 2020