Matlab基本函数-format函数1、format函数:控制输出、显⽰格式
2、⽤法说明
format 缺省格式,同short。Matlab中常⽤的显⽰格式有:
(1)format short表⽰5位近似定点数
(2)format long 15位近似定点数
(3)format hex ⼗六进制表⽰
(4)format bank 银⾏格式,固定元和分
(5)format rat 最⼩证书⽐例(分数)表⽰
3、⽤法举例
>> pi
ans =
3.1416
>> format
>> pi
ans =
3.1416
>> format short
>> pi
ans =
3.1416
>> format long
>> pi
ans =
3.141592653589793
>> format hex
>> pi
ans =
400921fb54442d18
>> format bank
>> pi
ans =
3.14
>> format rat
>> pi
ans =
355/113
4、附录
>> help format
format Set output format.
format with no inputs sets the output format to the default appropriate
for the class of the variable. For float variables, the default is
format SHORT.
format does not affect how MATLAB computations are done. Computations on float variables, namely single or double, are done in appropriate
switch函数用法举例floating point precision, no matter how those variables are displayed.
Computations on integer variables are done natively in integer. Integer
variables are always displayed to the appropriate number of digits for
the class, for example, 3 digits to display the INT8 range -128:127.
format SHORT and LONG do not affect the display of integer variables.
format SHORT and LONG do not affect the display of integer variables.
format may be used to switch between different output display formats of all float variables as follows:
format SHORT Scaled fixed point format with 5 digits.
format LONG Scaled fixed point format with 15 digits for double
and 7 digits for single.
format SHORTE Floating point format with 5 digits.
format LONGE Floating point format with 15 digits for double and
7 digits for single.
format SHORTG Best of fixed or floating point format with 5
digits.
format LONGG Best of fixed or floating point format with 15
digits for double and 7 digits for single.
format SHORTENG Engineering format that has at least 5 digits
and a power that is a multiple of three
format LONGENG Engineering format that has exactly 16 significant digits and a power that is a multiple of three.
format may be used to switch between different output display formats of all numeric variables as follows:
format HEX Hexadecimal format.
format + The symbols +, - and blank are printed
for positive, negative and zero elements.
Imaginary parts are ignored.
format BANK Fixed format for dollars and cents.
format RAT Approximation by ratio of small integers. Numbers
with a large numerator or large denominator are
replaced by *.
format may be used to affect the spacing in the display of all
variables as follows:
format COMPACT Suppresses extra line-feeds.
format LOOSE Puts the extra line-feeds back in.
Example:
format short, pi, single(pi)
displays both double and single pi with 5 digits as 3.1416 while
format long, pi, single(pi)
displays pi as 3.141592653589793 and single(pi) as 3.1415927.
format, intmax('uint64'), realmax
shows these values as 18446744073709551615 and 1.7977e+308 while format hex, intmax('uint64'), realmax
shows them as ffffffffffffffff and 7fefffffffffffff respectively.
The HEX display corresponds to the internal representation of the value and is not the same as the hexadecimal notation in the C programming language.
See also disp, display, isnumeric, isfloat, isinteger.
Reference page in Help browser
doc format
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论