MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1

Convert from Numeric Values to Character Array


In this section...
“Function Summary” on page 6-61
“Convert Numbers to Character Codes” on page 6-62
“Represent Numbers as Text” on page 6-62
“Convert to Specific Radix” on page 6-62

Function Summary


The functions listed in this table provide a number of ways to convert numeric data to
character arrays.

Function Description Example
char Convert a positive integer to an equivalent character.
(Truncates any fractional parts.)

[72 105] → 'Hi'

string Convert an array of double-precision values to a
string array.

[72 105] → "72"


"105"


[3.1416 2.178] →


"3.1416" "2.178"


int2str Convert a positive or negative integer to a character
type. (Rounds any fractional parts.)

[72 105] → '72 105'


num2str Convert a numeric type to a character type of the
specified precision and format.

[72 105] →


'72/105/' (format set
to %1d/)
mat2str Convert a numeric type to a character type of the
specified precision, returning a character vector
MATLAB can evaluate.

[72 105] → '[72


105]'


dec2hex Convert a positive integer to a character type of
hexadecimal base.

[72 105] → '48 69'


dec2bin Convert a positive integer to a character type of
binary base.

[72 105] → '1001000


1101001'


Convert from Numeric Values to Character Array
Free download pdf