Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
5.3.0 - 日本語

Change language to:
English - 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 manual >> Functions > functions

functions

Scilab プロシージャおよび Scilab オブジェクト

説明

functions は Scilab プロシージャ ("macro", "function" および "procedure" have the save meaning)です.

関数定義

通常,これらはエディタによりファイルで定義され, exec関数またはライブラリ (lib または genlib参照) によりScilabにロードされます. しかし,オンライン定義 (deff または function参照) することも可能です. 関数は以下の2つの要素により定義されます::

  • 以下のような "構文定義" 部:

    function [y1, ..., yn]=foo(x1, ...,xm)
    function [y1, ..., yn, varargout]=foo(x1, ...,xm,varargin)
  • 一連のScilab命令.

"構文定義" 行はこの関数の"完全な"呼び出し手順を指定します. yi は,入力変数xiと その関数が実行された際にScilabに存在する変数の関数として 計算される出力変数です.

呼び出し手順

  • 通常,関数の呼び出し手順は [y1,...,yn]=foo(x1,...,xm)となります. 入力または出力引数の一覧を定義より短くすることができます. このような場合, 左辺の先頭のいくつかの変数のみが使用され設定されます.

    呼び出し時の引数の実際の数は, argn により取得することができます.

  • It is possible to define function with indeterminate number of input or output maximum number of arguments. This can be done using the varargin and varargout keywords. See the given links for details.

  • It is also possible to use "named argument" to specify input arguments: suppose function fun1 defined as function y1=fun1(x1,x2,x3) then it can be called with a syntax like y=fun1(x1=33,x3=[1 2 3]) within fun1 x2 will be undefined,

    it can also be called with a syntax like y=fun1(x1=33,y='foo'). In such a case the y variable will be available in the context of the function fun1. Note that the maximum number of argument must be less or equal to the number of formal input argument used in the function syntax part.

    It is possible to check for defined variables with the exists function.

  • When a function has no left hand side argument and is called only with character string arguments, the calling syntax may be simplified:

    fun('a','toto','a string')

    is equivalent to:

    fun a toto 'a string'

Miscellaneous

Functions are Scilab objects (with type numbers 13 or 11). They and can be manipulated (built, saved, loaded, passed as arguments,..) as other variable types.

Collections of functions can be collected in libraries. Functions which begin with % sign (e.g. %foo) are often used to overload (see overloading ) operations or functions for new data type.

//インライン定義 (function参照)
function [x, y]=myfct(a, b)
  x=a+b
  y=a-b
endfunction

[x,y]=myfct(3,2)

//インライン定義 (deff参照)
deff('[x,y]=myfct(a,b)',['x=a+b';
                         'y=a-b'])
// アスキーファイルで定義 (exec参照)
exec SCI/modules/elementary_functions/macros/asinh.sci;
<< function Functions genlib >>

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 Jan 26 16:25:14 CET 2011