format
Set output display format
Description
format( changes the output
display format to the format specified by style)style. For example,
format("shortG") displays numeric values in a compact
form with 5 total digits. Numeric formats affect only how numbers appear in the
display, not how MATLAB® computes or saves them.
When you specify the style by name, you can use command form without parentheses or quotes:
format shortG
stores the current display format in fmt = 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)Examples
Input Arguments
Output Arguments
Tips
The specified format applies only to the current MATLAB session. To maintain a format across sessions, choose a Numeric format or Line spacing option in the Command Window settings.
You can specify
shortorlongand the presentation type separately, such asformat short Eorformat("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 display
int8data types (for instance, -128:127). Setting the output format toshortorlongdoes 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 using
shortG. See Large Data Range Format.