ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

MATLAB——数据输出格式

2022-05-27 01:02:12  阅读:203  来源: 互联网

标签:输出 10 character number values MATLAB characters 格式 pi


fileID

One of the following:

  • An integer file identifier obtained from fopen.

  • 1 for standard output (the screen).

  • 2 for standard error.

Default: 1 (the screen)

format

String in single quotation marks that describes the format of the output fields. Can include combinations of the following:

  • Percent sign followed by a conversion character, such as '%s' for strings.

  • Operators that describe field width, precision, and other options.

  • Literal text to print.

  • Escape characters, including:

    ''

    Single quotation mark

    %%

    Percent character

    \\

    Backslash

    \a

    Alarm

    \b

    Backspace

    \f

    Form feed

    \n

    New line

    \r

    Carriage return

    \t

    Horizontal tab

    \v

    Vertical tab

    \xN

    Hexadecimal number,N

    \N

    Octal number, N

Conversion characters and optional operators appear in the following order (includes spaces for clarity):

The following table lists the available conversion characters and subtypes.

Value TypeConversionDetails

Integer, signed

%d or %i

Base 10 values

%ld or %li

64-bit base 10 values

%hd or %hi

16-bit base 10 values

Integer, unsigned

%u

Base 10

%o

Base 8 (octal)

%x

Base 16 (hexadecimal), lowercase letters af

%X

Same as %x, uppercase letters AF

%lu
%lo
%lx or %lX

64-bit values, base 10, 8, or 16

%hu
%ho
%hx or %hX

16-bit values, base 10, 8, or 16

Floating-point number

%f

Fixed-point notation

%e

Exponential notation, such as3.141593e+00

%E

Same as %e, but uppercase, such as3.141593E+00

%g

The more compact of %e or %f, with no trailing zeros

%G

The more compact of %E or %f, with no trailing zeros

%bx or %bX
%bo
%bu

Double-precision hexadecimal, octal, or decimal value
Example: %bx prints pi as 400921fb54442d18

%tx or %tX
%to
%tu

Single-precision hexadecimal, octal, or decimal value
Example: %tx prints pi as 40490fdb

Characters

%c

Single character

%s

String of characters

Additional operators include:

  • Field width

    Minimum number of characters to print. Can be a number, or an asterisk (*) to refer to an argument in the input list. For example, the input list ('d', intmax) is equivalent to ('%*d', 12, intmax).

  • Precision

    For %f, %e, or %E:

    Number of digits to the right of the decimal point.
    Example: '%6.4f' prints pi as '3.1416'

    For %g or %G

    Number of significant digits.
    Example: '%6.4g' prints pi as ' 3.142'

    Can be a number, or an asterisk (*) to refer to an argument in the input list. For example, the input list ('%6.4f', pi) is equivalent to ('%*.*f', 6, 4, pi).

  • Flags

    Action

    Flag

    Example

    Left-justify.

    '–'

    %-5.2f

    Print sign character (+ or ).

    '+'

    %+5.2f

    Insert a space before the value.

    ' '

    % 5.2f

    Pad with zeros.

    '0'

    .2f

    Modify selected numeric conversions:

    • For %o, %x, or %X, print 0, 0x, or 0X prefix.

    • For %f, %e, or %E, print decimal point even when precision is 0.

    • For %g or %G, do not remove trailing zeros or decimal point.

    '#'

    %#5.0f

  • Identifier

    Order for processing inputs. Use the syntax n$, where n represents the position of the value in the input list.

    For example, '%3$s %2$s %1$s %2$s' prints inputs 'A', 'B', 'C' as follows: C B A B.

The following limitations apply to conversions:

  • Numeric conversions print only the real component of complex numbers.

  • If you apply an integer or string conversion to a numeric value that contains a fraction, MATLAB overrides the specified conversion, and uses %e.

  • If you apply a string conversion (%s) to integer values, MATLAB converts values that correspond to valid character codes to characters. For example, '%s'converts [65 66 67] to ABC.

  • Different platforms display exponential notation (such as %e) with a different number of digits in the exponent.

    Platform

    Example

    Windows

    1.23e+004

    UNIX

    1.23e+04
  • Different platforms display negative zero (-0) differently.

    Conversion Character

    Platform

    %e or %E

    %f

    %g or %G

    Windows

    0.000000e+000

    0.000000

    0

    Others

    -0.000000e+00

    -0.000000

    -0

A

Numeric or character array.

标签:输出,10,character,number,values,MATLAB,characters,格式,pi
来源: https://www.cnblogs.com/cnlntr/p/16316005.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有