Main Content

echo

Display statements during function or script execution

Description

example

echo onturns 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 offturns off echoing for statements in all script files.

echotoggles on and off echoing for statements in all script files.

example

echofilenameonturns on echoing for the function specified byfilename.

echofilenameoffturns off echoing for the function specified byfilename.

echofilenametoggles on and off the echoing of statements for the function specified byfilename.

echo on allturns on echoing for all functions.

echo off allturns off echoing for all functions.

Examples

collapse all

打开呼应的声明s 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)

打开呼应的声明s in all scripts, and then runnumGenerator. MATLAB displays each statement innumGeneratorin the Command Window as they execute.

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

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

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

echobuggyonbuggy(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 useonoroffas a function name.

Version History

Introduced before R2006a