将数据格式化为字符串或字符向量
Formats the data in arraysstr
= sprintf(FormatSpec
,,,,一种1,...,An
)一种1,...,An
using the formatting operators specified byFormatSpec
并返回结果文字str
。这Sprintf
Function formats the values in一种1,...,An
按列顺序。如果FormatSpec
是字符串,然后输出也是str
。Otherwise,str
是一种character vector.
返回多个块格式化文本的年代tring array or a cell array of character vectors, use the撰写
功能。
[[
返回一种nerror message as a character vector when the operation is unsuccessful. Otherwise,str
,,,,errmsg
] = sprintf(FormatSpec
,,,,一种1,...,An
)errmsg
是empty.
translates escape-character sequences instr
= sprintf(literalText
)literalText
, 如\n
一种nd\t
。It returns all other characters unaltered. IfliteralText
contain a formatting operator (such as%F
),,,,thenstr
discards it and all characters after.
这Sprintf
Function is similar toFprintf
,,,,butFprintf
prints to a file or to the Command Window.
为了mat specifiers for the reading functionssscanf
一种ndfscanf
differ from the formats for the writing functionsSprintf
一种ndFprintf
。阅读功能不支持精度字段。金宝app宽度字段指定写作的最低限度,但最大的阅读。
如果指定无效格式操作员或特殊字符,则Sprintf
prints all text up to the invalid operator or character and discards the rest.
Example:如果FormatSpec
是'value = %z'
, 然后Sprintf
prints'value ='
因为%z
不是格式操作员。
Example:如果FormatSpec
是'角色\ x99999 =%s'
, 然后Sprintf
prints'特点'
因为\ x99999
是not a valid special character.
[[1] Kernighan, B. W., and D. M. Ritchie,这CProgramming Language,,,,Second Edition, Prentice-Hall, Inc., 1988.
[2] ANSI规范x3.159 - 1989:“编程L一种nguage C,” ANSI, 1430 Broadway, New York, NY 10018.