Main Content

Format Output

MATLAB® displays output in both the Command Window and the Live Editor. You can format the output display using several provided options.

Format Line Spacing in Output

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.

Format Floating-Point Numbers

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 FormatExample Output

short (default)

x = 1.3333 0.0000

short e

x = 1.3333e+00 1.2345e-06

long

x = 1.333333333333333 0.000001234500000

+

x = ++

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.

Wrap Lines of Code to Fit Window Width

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:

  1. On the Home tab, in the Environment section, click Preferences. Select MATLAB > Command Window.

  2. Select Wrap Lines.

  3. Click OK.

Note

Line wrapping options do not apply in the Live Editor.

Suppress Output

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);

View Output by Page

Output in the Command Window might exceed the visible portion of the window. You can view the output, one screen at a time:

  1. In the Command Window, type more on to enable paged output.

  2. Type the command that generates large output.

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

Clear the Command Window

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.

See Also

| | |