Skip to Main Content Skip to Search
Product Documentation

Command Window Code and Output Display

Keep or Suppress Blank Lines in Output

By default, MATLAB displays blanks lines in command output.

To control the display of blank lines in output:

  1. Select File > Preferences > Command Window.

  2. Select a Numeric format:

    • loose—Keeps the display of blank lines

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

  3. Click OK.

Alternatively, use the format function with the loose or compact option.

Format Numerals

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:

To change the numeric display option, do one of the following:

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

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. In console mode, it can be useful to make a single line of input or output in the Command Window break into multiple lines to fit within the current width of the Command Window.

To wrap lines of code:

  1. Select File > Preferences > Command Window.

  2. Select Wrap Lines.

  3. Click OK.

Matrix Display Width

By default, a row of matrix output fills the width of the Command Window, and then continues displaying output in a new row.

To determine the number of characters and lines that will display in the Command Window, given its current size, use:

get(0,'CommandWindowSize')

For example, a result of 50, 25 means 50 characters will display across the Command Window, and 25 lines will display.

To set the matrix output to 80 characters per row (and then continue displaying output in a new row, regardless of the width of the Command Window) :

  1. Select File > Preferences > Command Window.

  2. Select Set matrix display width to eighty columns.

      Note   If you also select Wrap lines, and the width of the Command Window is less than 80 characters, each row of 80 characters of matrix output wraps to fit within the width of the Command Window.

  3. Click OK.

Run get(0,'CommandWindowSize') again. The result for the same size Command Window is 80, 25.

Number of Spaces Assigned to Tab Key

By default, a tab is set to four spaces, except on UNIX[1] platforms where the default is eight spaces.

To change the setting:

  1. Select File > Preferences > Command Window.

  2. Type a new value in the Tab size field.

  3. Click OK.

Suppress Code Output

To suppress code output, add a semicolon (;) to the end of a command. This is particularly useful when code generates large matrices. For example, running the following code creates A, but does not show the resulting matrix in the Command Window:

A = magic(100);

Page Code Output

When output in the Command Window exceeds the visible portion of the window, follow these steps to view the output, one screen full at a time:

  1. In the Command Window, type more on.

  2. View the remaining 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.

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:


[1] UNIX is a registered trademark of The Open Group in the United States and other countries.

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS