Format Output in Command Window

Format Line Spacing in Output

By default, MATLAB® displays blanks lines in command output.

You can select one of two numeric display 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 format the output 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 at the command line, for example:

    format loose
    format compact

Format Floating-Point Numbers

You can change the way numbers display. By default, MATLAB uses the short format (5-digit scaled, fixed-point values).

For example, suppose you enter x = [4/3 1.2345e-6] in the Command Window. The MATLAB output display depends on the format you selected.

Output Display FormatExample Output

short (default)

x = 1.3333 0.0000

short e

x = 1.3333e+00 1.2345e-06

+

x = ++

    Note:   The text display format affects only how numbers are shown, not how MATLAB computes or saves them.

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.

Suppress Output

To suppress code output, add a semicolon (;) to the end of a command. This is particularly useful when code generates large matrices.

Running the following code creates A, but does not show the resulting matrix in the Command Window:

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.

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

| | |

Was this topic helpful?