echo - Display statements during function or script execution - MATLAB (original) (raw)

Main Content

Display statements during function or script execution

Syntax

Description

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.

example

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

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

echo [filename](#mw%5F3bf59204-dc26-47f9-85cf-5db7171e9a63) on turns on echoing for the function specified by filename.

example

echo [filename](#mw%5F3bf59204-dc26-47f9-85cf-5db7171e9a63) off turns off echoing for the function specified by filename.

echo [filename](#mw%5F3bf59204-dc26-47f9-85cf-5db7171e9a63) toggles on and off the echoing of statements for the function specified byfilename.

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 runnumGenerator. MATLAB displays each statement in numGenerator in the Command Window as they execute.

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

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

Version History

Introduced before R2006a