Convert from Character Arrays to Numeric Values
In this section...
“Function Summary” on page 6-63
“Convert from Character Code” on page 6-64
“Convert Text that Represents Numeric Values” on page 6-64
“Convert from Specific Radix” on page 6-65
Function Summary
The functions listed in this table provide a number of ways to convert character arrays to
numeric data.
Function Description Example
uintN (e.g., uint8) Convert a character to an integer code that
represents that character.
'Hi' → 72 105
str2num Convert a character type to a numeric type. '72 105' → [72 105]
str2double Similar to str2num, but offers better
performance and works with string arrays and
cell arrays of character vectors.
"72" "105" → [72
105]
{'72' '105'} → [72
105]
hex2num Convert a numeric type to a character type of
specified precision, returning a character array
that MATLAB can evaluate.
'A' → '-1.4917e-154'
hex2dec Convert a character type of hexadecimal base to
a positive integer.
'A' → 10
bin2dec Convert a character type of binary number to a
decimal number.
'1010' → 10
base2dec Convert a character type of any base number
from 2 through 36 to a decimal number.
'12' → 10 (if base ==
8 )
Convert from Character Arrays to Numeric Values