Page 91 - Basics of MATLAB and Beyond
P. 91

ans  =
                               3.14159e+100

                               Some additional text can be mixed with the numerical conversion, for
                               example:

                               >> num2str(pi,’Pi has a value of %12.5e, or thereabouts.’)
                               ans  =
                               Pi has a value of   3.14159e+00, or thereabouts.
                                            9
                               The online help entry for the sprintf command gives a full description
                               of how to use the various formatting options. (The sprintf command
                               is the matlab version of the C language command of the same name.)
                               The following table is taken from the online help.
                                %c   Single character
                                %d   Decimal notation (signed)
                                %e   Exponential notation (using a lowercase e as in 3.1415e+00)
                                %E   Exponential notation (using an uppercase E as in 3.1415E+00)
                                %f   Fixed-point notation
                                %g   The more compact of %e or %f. Insignificant zeros do not print.
                                %G   Same as %g, but using an uppercase E
                                %o   Octal notation (unsigned)
                                %s   String of characters
                                %u   Decimal notation (unsigned)
                                %x   Hexadecimal notation (using lowercase letters a-f)
                                %X   Hexadecimal notation (using uppercase letters A-F)
                                  To further control the formatting, other characters can be inserted
                               into the conversion specifier between the % and the conversion character:

                                Character          What it does
                                A minus sign (-)   Left-justifies the converted argument in its
                                                   field.
                                A plus sign (+)    Always prints a sign character (+ or −).
                                Zero (0)           Pads with zeros rather than spaces.
                                Digits (field width)  Specifies the minimum number of digits to be
                                                   printed.
                                Digits (precision)  Specifies the number of digits to be printed to
                                                   the right of the decimal point.

                                 9 Type helpdesk at the command line to get hypertext help.









                               c   2000 by CRC Press LLC
   86   87   88   89   90   91   92   93   94   95   96