MATLAB® displays output in both the Command Window and the Live Editor. You can format the output display using several provided options.
By default, MATLAB displays blanks lines in Command Window output.
You can select one of two line spacing options in MATLAB.
loose
— Keeps the display of blank lines
(default).
>> x = [4/3 1.2345e-6] x = 1.3333 0.0000
compact
— Suppresses the display of blank
lines.
>> x = [4/3 1.2345e-6] x = 1.3333 0.0000
To change the line spacing option, do one of the following:
On the Home tab, in the
Environment section, click
Preferences. Select MATLAB > Command Window, and then choose a Line spacing
option.
Use the format
function at the command line, for
example:
format loose format compact
Note
Line spacing options do not apply in the Live Editor.
You can change the way numbers display in both the Command Window and the Live Editor. By default, MATLAB uses the short format (5-digit scaled, fixed-point values).
For example, suppose that you enter x = [4/3 1.2345e-6]
in the
Command Window. The MATLAB output display depends on the format you selected. This table shows
some of the available numeric display formats, and their corresponding
output.
Numeric Display Format | Example Output |
---|---|
|
|
|
|
|
|
|
|
Note
The text display format affects only how numbers are shown, not how MATLAB computes, or saves them.
To format the way numbers display, do one of the following:
On the Home tab, in the
Environment section, click
Preferences. Select MATLAB > Command Window, and then choose a Numeric format
option.
Use the format
function, for
example:
format short format short e format long
See the format
reference page
for a list and description of all supported numeric formats.
A line of code or its output can exceed the width of the Command Window, requiring you to use the horizontal scroll bar to view the entire line. To break a single line of input or output into multiple lines to fit within the current width of the Command Window:
On the Home tab, in the
Environment section, click
Preferences. Select MATLAB > Command Window.
Select Wrap Lines.
Click OK.
Note
Line wrapping options do not apply in the Live Editor.
To suppress code output, add a semicolon (;) to the end of a command. This is useful when code generates large matrices.
Running the following code creates A
, but does not show the
resulting matrix in the Command Window or the Live
Editor:
A = magic(100);
Output in the Command Window might exceed the visible portion of the window. You can view the output, one screen at a time:
In the Command Window, type more on
to enable paged
output.
Type the command that generates large output.
View the output:
Advance to the next line by pressing Enter.
Advance to the next page by pressing Space Bar.
Stop displaying the output by pressing q.
To disable paged output, type more off
.
Note
Paged output options do not apply in the Live Editor.
If the Command Window seems cluttered, you can clear all the text (without clearing the workspace) by doing one of the following:
On the Home tab, in the Code section, select Clear Commands > Command Window to clear the Command Window scroll buffer.
Use the clc
function to clear the Command Window scroll
buffer.
Use the home
function to clear your current view of the
Command Window, without clearing the scroll buffer.