Matlab基本函数-format函数

来源:互联网 发布:sas软件是什么 编辑:程序博客网 时间:2024/04/30 18:23

1、format函数:控制输出、显示格式

2、用法说明

     format 缺省格式,同short。Matlab中常用的显示格式有:

(1)format short表示5位近似定点数

(2)format long 15位近似定点数

(3)format hex 十六进制表示

(4)format bank 银行格式,固定元和分

(5)format rat 最小证书比例(分数)表示

3、用法举例

>> pians =    3.1416>> format>> pians =    3.1416>> format short>> pians =    3.1416>> format long >> pians =   3.141592653589793>> format hex>> pians =   400921fb54442d18>> format bank>> pians =          3.14>> format rat>> pians =     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    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 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