Main Content

echo

Display statements during function or script execution

Description

example

echo on turns on echoing for statements in all script files. When you turn on echoing, MATLAB® displays each line in the file in the Command Window as it runs. Normally, the statements in a script are not displayed during execution. Statement echoing is useful for debugging and for demonstrations.

echo off turns off echoing for statements in all script files.

echo toggles on and off echoing for statements in all script files.

example

echo filename on turns on echoing for the function specified by filename.

echo filename off turns off echoing for the function specified by filename.

echo filename toggles on and off the echoing of statements for the function specified by filename.

echo on all turns on echoing for all functions.

echo off all turns off echoing for all functions.

Examples

collapse all

Turn on echoing for statements in all scripts, and then run a script.

Create a script, numGenerator.m, that generates random numbers between 0 and 100.

columns = 10000;
rows = 1;
bins = columns/100;

rng(now);
list = 100*rand(rows,columns);
histogram(list,bins)

Turn on echoing for statements in all scripts, and then run numGenerator. MATLAB displays each statement in numGenerator in the Command Window as they execute.

echo on
numGenerator
columns = 10000;
rows = 1;
bins = columns/100;

rng(now);
list = 100*rand(rows,columns);
histogram(list,bins)

Turn on echoing of statements for a function, and then run the function.

Create a file, buggy.m, that contains these statements.

function z = buggy(x)
n = length(x);
z = (1:n)./x;
end

Turn on echoing of statements for the function buggy, and then run the function. MATLAB displays each statement in buggy in the Command Window as they execute, then displays the output of buggy.

echo buggy on
buggy(1:5)
function z = buggy(x)
n = length(x);
z = (1:n)./x;
end

ans =

     1     1     1     1     1

Input Arguments

collapse all

File name of the function to turn echoing on and off for, specified as a character vector or string scalar.

Example: echo buggy on

Tips

  • Running MATLAB with echoing turned on is inefficient. To improve performance, only turn echoing on for debugging or demonstration purposes.

  • To avoid confusing syntax, do not use on or off as a function name.

Version History

Introduced before R2006a

See Also

| |