Set output display format for Command Window
format(
changes the output display format in the Command Window to the format specified bystyle
)style
. For example,format("shortG")
displays numeric values in a compact form with 5 total digits. Numeric formats affect only how numbers appear in Command Window output, not how MATLAB®computes or saves them.
When you specify the style by name, you can usecommand formwithout parentheses or quotes:
formatshortG
stores the current display format infmt
= format(style
)fmt
and then changes the display format to the specified style. (since R2021a)
You cannot use command form when you request output or when you pass a variable as input. Enclose inputs in parentheses and include style names in quotes.
fmt = format("shortG"); format(fmt)
The specified format applies only to the current MATLAB session. To maintain a format across sessions, choose aNumeric formatorLine spacingoption in the Command Window preferences.
You can specifyshort
orlong
and the presentation type separately, such asformat short E
orformat("short E")
.
MATLAB always displays integer data types to the appropriate number of digits for the data type. For example, MATLAB uses 3 digits to displayint8
data types (for instance, -128:127). Setting the output format toshort
orlong
does not affect the display of integer-type variables.
Integer-valued, floating-point numbers with a maximum of 9 digits do not display in scientific notation.
If you are displaying a matrix with a wide range of values, consider usingshortG
. SeeLarge Data Range Format.