MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1
Special Character Representation in Format
Specifier
Character whose Unicode numeric value can be
represented by the hexadecimal number, N

\xN

Example: sprintf('\x5A')
returns 'Z'
Character whose Unicode numeric value can be
represented by the octal number, N

\N


Example: sprintf('\132')
returns 'Z'

Setting Field Width and Precision


The formatting operator follows a set of rules for formatting output text to the specified
field width and precision. You also can specify values for the field width and precision
outside the format specifier, and use numbered identifiers with the field width and
precision.

Rules for Formatting Precision and Field Width

The figure illustrates how the field width and precision settings affect the output of the
formatting functions. In this figure, the zero following the % sign in the formatting
operator means to add leading zeroes to the output text rather than space characters.


  • If the precision is not specified, then it defaults to six.

  • If the precision p is less than the number of digits in the fractional part of the input,
    then only p digits are shown after the decimal point. The fractional value is rounded in
    the output.


6 Characters and Strings

Free download pdf