Print this article Edit this article

MatLab: Changing the format of the output in Matlab

Matlab displays the results of any assignments statement on the screen, and assigns it to the specified variable, or to ans if no variable is given. You can use the format command control the numeric display format. The format command affects only how numbers are displayed, not how they are computed or saved.

If all the elements of a matrix are exact integers, the matrix displays in a format without any decimal points. For example

x = [-1 0 1]

always results in

x = -1 0 1

If at least one element of a matrix is not an exact integer, several output formats are possible. The default format, called the short format, shows approximately five significant decimal digits. The other formats show more significant digits or use scientific notations. As an example, suppose

x = [4/3 1.2345e-6]

The formats, and the resulting output for this vector, are:

  • format short
    1.3333 0.0000

     

  • format short e
    1.3333e+00 1.2345e-06

     

  • format long
    1.33333333333333 0.00000123450000

     

  • format long e
    1.333333333333333e+00 1.234500000000000e-06

     

  • format bank
    1.33 0.00

     

  • format hex
    3ff5555555555555 3eb4b6231abfd271

     

  • format +
    ++

With the short and long formats, if the largest element of a matrix is larger than 1000 or smaller than 0.001, a common scale factor is applied to the entire matrix when it is displayed.

The + format is a compact way to display large matrices. The symbols +, -, and blank display for positive, negative, and zero elements.

A final format command, format compact, suppresses many line-feeds that appear between matrix displays and allows more information to show on the screen.

Last Modified: Dec 19, 2016 11:12 am US/Eastern
Created: Oct 8, 2007 9:22 am GMT-4 by admin
JumpURL: