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

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 help >> Functions > execstr

execstr

文字列中のScilabコードを実行

呼び出し手順

execstr(instr)
ierr=execstr(instr,'errcatch' [,msg])

パラメータ

instr

文字列のベクトル, 実行するScilab命令.

ierr

整数, 0 ばたはエラー番号.

msg

'm' または'n' を有する文字列. デフォルト値は'n'.

説明

引数instrで指定したScilab命令を実行します.

instr の中では継続記号 (..) を使用する必要は ないことに注意してください.

'errcatch'フラグが指定されない場合, エラー処理は通常と同様に行われます.

'errcatch'フラグが指定された場合, instrで定義された命令を実行す際に 発生したエラーはエラーメッセージを発生せず, instr 命令の実行を (エラーが発生した場所で)破棄し, エラー番号に等しいierrを返して 復帰します. この場合,エラーメッセージの出力は msgオプションにより次のように 制御されます:

"m"

エラーメッセージは表示され,記録されます.

"n"

エラーメッセージは表示されませんが, 記録されます ( lasterror参照). これがデフォルトです.

ierr=execstr(instr,'errcatch') は構文エラーも 処理することができます. この特徴は,ユーザへの問い合わせにより得られた命令を 評価する際に有用です.

execstr('a=1') // sets a=1.
execstr('1+1') // does nothing (while evstr('1+1') returns 2)

execstr(['if %t then';
         '  a=1';
         '  b=a+1';
         'else'
         ' b=0'
         'end'])

execstr('a=zzzzzzz','errcatch')
execstr('a=zzzzzzz','errcatch','m')

//syntax errors
execstr('a=1?02','errcatch')
lasterror(%t)

execstr('a=[1 2 3)','errcatch')
lasterror(%t)

// variable1 does not exist
if execstr('variable1;','errcatch')<>0 then disp("Trigger an error"),end

// variable2 exists ... no error is triggered by execstr
variable2=[2,3]; 
if execstr('variable2;','errcatch')<>0 then 
   disp("Trigger an error");
else
   disp("execstr is happy");
end

参照

  • evstr — 式の評価
  • lasterror — 直近に記録されたエラーメッセージを取得
  • error — エラーメッセージ
  • try — try-catch 制御命令のtryブロックを開始
<< exec Functions fun2string >>

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:
Thu Mar 03 11:01:00 CET 2011