12.07.2015 Views

Basics of MATLAB and Beyond

Basics of MATLAB and Beyond

Basics of MATLAB and Beyond

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

ans =3.14159e+100Some additional text can be mixed with the numerical conversion, forexample:>> num2str(pi,’Pi has a value <strong>of</strong> %12.5e, or thereabouts.’)ans =Pi has a value <strong>of</strong> 3.14159e+00, or thereabouts.The online help 9 entry for the sprintf comm<strong>and</strong> gives a full description<strong>of</strong> how to use the various formatting options. (The sprintf comm<strong>and</strong>is the matlab version <strong>of</strong> the C language comm<strong>and</strong> <strong>of</strong> 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 <strong>of</strong> %e or %f. Insignificant zeros do not print.%G Same as %g, but using an uppercase E%o Octal notation (unsigned)%s String <strong>of</strong> 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 insertedinto the conversion specifier between the % <strong>and</strong> the conversion character:CharacterA minus sign (-)A plus sign (+)Zero (0)Digits (field width)Digits (precision)What it doesLeft-justifies the converted argument in itsfield.Always prints a sign character (+ or −).Pads with zeros rather than spaces.Specifies the minimum number <strong>of</strong> digits to beprinted.Specifies the number <strong>of</strong> digits to be printed tothe right <strong>of</strong> the decimal point.9 Type helpdesk at the comm<strong>and</strong> line to get hypertext help.c○ 2000 by CRC Press LLC

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!