| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → MATLAB |
| Contents | Index |
| Learn more about MATLAB |
| On this page… |
|---|
Paging of Output in the Command Window Formatting and Spacing Numeric Output Number of Characters in Command Window Display |
Echoing command execution is useful for debugging or for demonstrations. It enables you to view commands as they execute. To display each function within a statement as it executes, type echo on in the Command Window. For details, see the echo reference page.
If you end a statement with a semicolon ( ; ) and then press Enter or Return, the MATLAB software runs the statement, but does not display any output. This is particularly useful when you generate large matrices. For example, running the following code creates A but does not show the resulting matrix in the Command Window:
A = magic(100);
Issue the more on command to control the paging of output in the Command Window. This is useful, for example, if output in the Command Window exceeds the visible portion of the window. You then have to scroll backward to review all the output. By default, more is off.
After you type more on, MATLAB displays only a page (a screen full) of output, pauses, and displays
--more--
indicating there is more output to display. Press one of the following keys.
Key | Action |
|---|---|
Enter or Return | To advance to the next line |
Space Bar | To advance to the next page |
q | To stop displaying the output |
By default, numeric output in the Command Window is displayed as 5-digit scaled, fixed-point values, called the short format. To change the numeric format of output for the current and future sessions, set the Command Window preference for text display. The text display format affects only how numbers are shown, not how MATLAB computes or saves them.
Use the format function to control the output format of the numeric values displayed in the Command Window. The format you specify applies until you change it or until the end of the session.
Here are a few examples of the various formats and the output produced from the following two-element vector x:
x = [4/3 1.2345e-6] format short 1.3333 0.0000 format short e 1.3333e+000 1.2345e-006 format + ++
A complete list and description of available formats is in the reference page for format. For more control over the output format, use the sprintf and fprintf functions.
To control spacing in the output, use the Command Window preference for text display or the format function. Use
format compact
to suppress blank lines, allowing you to view more information in the Command Window. To include the blank lines, which can help make output more readable, use
format loose
The maximum line length for Command Window display is 25,000 characters. If the output from a statement exceeds this limit, the Command Window truncates the output and displays the following message at the end of the line of output:
Output truncated. Text exceeds maximum line length of 25,000 characters for Command Window display.
Clear the Command Window view without clearing the workspace by selecting Edit > Clear Command Window.
Afterwards, unless you have changed the keyboard shortcut for it, you can use the up arrow it to recall previous functions from the command history.
For more information, see:
Use clc to clear the Command Window. Or, use the home function to move the prompt so that the screen is clear, but you can still scroll up to see the Command Window contents.
To print the contents of the Command Window, use one of the methods described in the table that follows.
| To | Do This |
|---|---|
Print the complete Command Window contents. | Select File > Print. |
Print a portion of the Command Window contents. | Select the text you want to print, and then select File > Print Selection. |
Specify printing options for the Command Window. (For example, you can specify a header.) | Select File > Page
Setup. For more information, see Printing and Page Setup Options for Desktop Tools. |
The diary function creates a copy of your session in MATLAB on a disk file, including keyboard input and system responses, but excluding graphics. You can view and edit the resulting text file using any text editor, such as the MATLAB Editor. To create a file on your disk called sept23.out that contains all the functions you enter, as well as output from MATLAB, type the following:
diary('sept23.out')
To stop recording the session, type:
diary('off')
To view the file, type:
edit('sept23.out')
There are two other means of viewing session information:
The Command History window contains a log of all functions executed in the current and previous sessions—see Using the Command History Window
The logfile startup option—see Startup Options.
![]() | Assistance While Entering Statements | Finding Text in the Command Window | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2010- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |