0

Question is simply: in MATLAB, you could simply use echo myFun on to set the echo status of a single function m-file to on, which then shows you each of the lines executed.

In GNU Octave, however, such a syntax is missing. help echo shows:

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.

Digging deeper, the info page says more:

 -- 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.

So something like my attempt below might potentially solve the problem; however, as the documentation suggests, it affects the function and any subroutines calls. So problem is still not solved; I thought I have answered my own question, but I found that I did not.

Simply add echo_executing_commands(2, 'local'); at the beginning of the function file needs debugging; in other words, open myFun.m, and insert the statement in the beginning of the function m-file. Note that this is only Octave function, so to be fully compatible, use:

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

1 Answer 1

0

This does not work

Simply add echo_executing_commands(2, 'local'); at the beginning of the function file needs debugging; in other words, open myFun.m, and insert the statement in the beginning of the function m-file. Note that this is only Octave function, so to be fully compatible, use:

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .