I read in the documentation that I can use the statement echo on; to have MATLAB print the statements it executes. However, I am having difficulties making this work inside a function.
For example:
function do_something(foo)
a = 2;
echo on;
foo = foo+1;
disp('This is a test');
foo = foo+3;
end
If I call do_something(foo) from the command window, I was expecting to see something like:
foo = foo+1;
disp('This is a test');
This is a test
foo = foo+3;
However, in the example above, all MATLAB prints is:
this is a test
which is not what I was expecting.
Update
As @Phonon explains below, echo on is only for scripts (sorry I missed that!). However, I read in the documentation that I can activate echo for a given function as follows:
echo fcnname on
So my question now is, is there a way to activate echo for a function using some variation of the syntax above so that I do this (call echo) inside a function? (the variable that holds the function name in this case would be provided by mfilename)
Update 2:
As far as I understand it is not possible to activate echo for a particular function inside the actual function. Among other things, it seems that MATLAB needs to know beforehand if the function has to run in "echo mode" to avoid using JIT.
According to Matlab documentation, i.e.
help echo,It will not work inside functions. To make it work for functions, according to that same help file,
Update:
In order to find which function you’re in currently, the best way I see of doing it is by calling
dbstack. Goes somewhat as follows: