Graphical Interface
As an alternative to format, use preferences. Select Preferences from the File menu in the MATLAB desktop and use Command Window preferences.
Syntax
Description
MATLAB performs all computations in double precision. Use the format function to control the output format of the numeric values displayed in the Command Window. The format function affects only how numbers are displayed, not how MATLAB computes or saves them. The specified format applies only to the current session. To maintain a format across sessions, instead use MATLAB preferences.
format by itself, changes the output format to the default type, short, which is 5-digit scaled, fixed-point values.
format changes the format to the specified type type. The table below describes the allowable values for type and provides an example for pi, unless otherwise noted. To see the current type file, use get(0,'Format'), or for compact versus loose, use get(0,'FormatSpacing').
format(' is the function form of the syntax.type')
Examples
Change the format to long by typing
View the result for the value of pi by typing
View the current format by typing
Set the format to short e by typing
or use the function form of the syntax
Algorithms
If the largest element of a matrix is larger than 103 or smaller than 10-3, MATLAB applies a common scale factor for the short and long formats. The function format + displays +, -, and blank characters for positive, negative, and zero elements. format hex displays the hexadecimal representation of a binary double-precision number. format rat uses a continued fraction algorithm to approximate floating-point values by ratios of small integers. See rat.m for the complete code.
No comments:
Post a Comment