23.06.2015 Views

MATLAB Programming

MATLAB Programming

MATLAB Programming

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Characters and Strings<br />

Converting from a Numeric String<br />

Use str2num to convert a character array to the numeric value represented by<br />

that string:<br />

str = '37.294e-1';<br />

val = str2num(str)<br />

val =<br />

3.7294<br />

The str2double function converts a cell array of strings to the<br />

double-precision values represented by the strings:<br />

c = {'37.294e-1'; '-58.375'; '13.796'};<br />

d = str2double(c)<br />

d =<br />

3.7294<br />

-58.3750<br />

13.7960<br />

whos<br />

Name Size Bytes Class<br />

c 3x1 224 cell<br />

d 3x1 24 double<br />

Converting from a Specific Radix<br />

To convert from a character representation of a nondecimal number to the<br />

value of that number, use one of these functions: hex2num, hex2dec, bin2dec,<br />

or base2dec.<br />

The hex2num and hex2dec functions both take hexadecimal (base 16) inputs,<br />

but hex2num returns the IEEE double-precision floating-point number it<br />

represents, while hex2dec converts to a decimal integer.<br />

2-63

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

Saved successfully!

Ooh no, something went wrong!