DisplayFormatOptions
Description
You can use the format
function to return information about
the current display format in the Command Window. That information is stored in a
DisplayFormatOptions
object. The object has two properties:
NumericFormat
stores the numeric display format, and
LineSpacing
stores the line spacing display format. You can also call
format
with a DisplayFormatOptions
object as the input
argument to restore the display settings saved in that object.
Creation
Create a DisplayFormatOptions
object by calling the format
function with an output argument.
Properties
NumericFormat
— Numeric display format
short
| long
| shortE
| longE
| ...
Numeric display format, specified as one of these options.
| Result | Example |
---|---|---|
short | Short, fixed-decimal format with 4 digits after the decimal point. This is the default numeric setting. | 3.1416 |
| Long, fixed-decimal format with 15 digits after the decimal point for | 3.141592653589793 |
| Short scientific notation with 4 digits after the decimal point. | 3.1416e+00 |
| Long scientific notation with 15 digits after the decimal point for | 3.141592653589793e+00 |
| Short, fixed-decimal format or scientific notation, whichever is more compact, with a total of 5 digits. | 3.1416 |
| Long, fixed-decimal format or scientific notation, whichever is more compact, with a total of 15 digits for | 3.14159265358979 |
| Short engineering notation (exponent is a multiple of 3) with 4 digits after the decimal point. | 3.1416e+000 |
| Long engineering notation (exponent is a multiple of 3) with 15 significant digits. | 3.14159265358979e+000 |
| Positive/Negative format with | + |
| Currency format with 2 digits after the decimal point. | 3.14 |
| Hexadecimal representation of a binary double-precision number. | 400921fb54442d18 |
| Ratio of small integers. | 355/113 |
LineSpacing
— Line spacing display format
compact
| loose
Line spacing display format, specified as compact
or
loose
.
| Result | Example |
---|---|---|
| Suppress excess blank lines to show more output on a single screen. | theta = pi/2 |
| Add blank lines to make output more readable. This is the default setting for line spacing. | theta = pi/2 |
Examples
Get Current Format
Since R2021a
Get the current display format.
fmt = format
fmt = DisplayFormatOptions with properties: NumericFormat: "short" LineSpacing: "loose"
Save and Restore Display Format
Since R2021a
Save the current display format and restore it at a later time.
Set the numeric display to shortE
and display a 2-by-2 matrix of numeric values.
format shortE
m = [9638573934 37467; 236 574638295]
m = 2×2
9.6386e+09 3.7467e+04
2.3600e+02 5.7464e+08
Save the current display format in oldFmt
and change the numeric format to longE
.
oldFmt = format("longE")
oldFmt = DisplayFormatOptions with properties: NumericFormat: "shortE" LineSpacing: "loose"
Confirm that the numeric format is now long, scientific notation by redisplaying matrix m
.
m
m = 2×2
9.638573934000000e+09 3.746700000000000e+04
2.360000000000000e+02 5.746382950000000e+08
Restore the format to its previous state. Redisplay m
to confirm that the numeric format is now short, scientific format.
format(oldFmt) m
m = 2×2
9.6386e+09 3.7467e+04
2.3600e+02 5.7464e+08
Version History
Introduced in R2021a
See Also
Abrir ejemplo
Tiene una versión modificada de este ejemplo. ¿Desea abrir este ejemplo con sus modificaciones?
Comando de MATLAB
Ha hecho clic en un enlace que corresponde a este comando de MATLAB:
Ejecute el comando introduciéndolo en la ventana de comandos de MATLAB. Los navegadores web no admiten comandos de MATLAB.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)