GNU Octave で単一ファイルの実行を表示する (echo fcnname on)

GNU Octave で単一ファイルの実行を表示する (echo fcnname on)

質問は簡単です。MATLABでは、単一のステータスecho myFun onを設定するためにecho関数m-file を にコピーするonと、実行された各行が表示されます。

しかし、GNU Octave にはそのような構文がありません。次のようhelp echoに表示されます。

octave:1> help echo
'echo' is a built-in function from the file libinterp/corefcn/input.cc

 -- Command: echo
 -- Command: echo on
 -- Command: echo off
 -- Command: echo on all
 -- Command: echo off all
     Control whether commands are displayed as they are executed.

     Valid options are:

     'on'
          Enable echoing of commands as they are executed in script
          files.

     'off'
          Disable echoing of commands as they are executed in script
          files.

     'on all'
          Enable echoing of commands as they are executed in script
          files and functions.

     'off all'
          Disable echoing of commands as they are executed in script
          files and functions.

     With no arguments, 'echo' toggles the current echo state.

Additional help for built-in functions and operators is
available in the online version of the manual.  Use the command
'doc <topic>' to search the manual index.

Help and information about Octave is also available on the WWW
at http://www.octave.org and via the [email protected]
mailing list.

さらに詳しく調べてみると、情報ページにはさらに詳しいことが書かれています。

 -- Built-in Function: VAL = echo_executing_commands ()
 -- Built-in Function: OLD_VAL = echo_executing_commands (NEW_VAL)
 -- Built-in Function: echo_executing_commands (NEW_VAL, "local")
     Query or set the internal variable that controls the echo state.

     It may be the sum of the following values:

     1
          Echo commands read from script files.

     2
          Echo commands from functions.

     4
          Echo commands read from command line.

     More than one state can be active at once.  For example, a value of
     3 is equivalent to the command 'echo on all'.

     The value of 'echo_executing_commands' may be set by the 'echo'
     command or the command line option '--echo-commands'.

     When called from inside a function with the "local" option, the
     variable is changed locally for the function and any subroutines it
     calls.  The original variable value is restored when exiting the
     function.

したがって、私が以下に試みたような方法では、潜在的に問題を解決できる可能性があります。ただし、ドキュメントに記載されているように、それは機能と どれでも サブルーチン呼び出しつまり、問題はまだ解決されていません。私は自分の疑問に自分で答えたと思っていましたが、そうではないことがわかりました。

デバッグが必要な関数ファイルの先頭にを追加するだけですecho_executing_commands(2, 'local');。つまり、 を開いてmyFun.m、関数mファイルの先頭に という文を挿入します。これはのみオクターブ関数なので、完全な互換性を保つには、次を使用します。

if exist('OCTAVE_VERSION', 'builtin') ~= 0; echo_executing_commands(2, 'local');end

答え1

これは動作しません

デバッグが必要な関数ファイルの先頭にを追加するだけですecho_executing_commands(2, 'local');。つまり、 を開いてmyFun.m、関数mファイルの先頭に という文を挿入します。これはのみオクターブ関数なので、完全な互換性を保つには、次を使用します。

if exist('OCTAVE_VERSION', 'builtin') ~= 0; echo_executing_commands(2, 'local');end

関連情報