Documentation Center

  • Trial Software
  • Product Updates


Convert to character array (string)


S = char(X)
S = char(C)
S = char(T1,T2,...,TN)


S = char(X) converts array X of nonnegative integer codes into a character array. Valid codes range from 0 to 65535, where codes 0 through 127 correspond to 7-bit ASCII characters. The characters that MATLAB® can process (other than 7-bit ASCII characters) depend upon your current locale setting. To convert characters into a numeric array, use the double function.

S = char(C), when C is a cell array of strings, places each element of C into the rows of the character array s. Use cellstr to convert back.

S = char(T1,T2,...,TN) forms the character array S containing the text strings T1, T2, ..., TN as rows, automatically padding each string with blanks to form a valid matrix. Each text parameter, Ti, can itself be a character array. This allows the creation of arbitrarily large character arrays. Empty strings are significant.


expand all

Convert Integers to Characters

Create a 3-by-32 array of the printable ASCII characters.

asc = char(reshape(32:127,32,3)')
asc =


See Also

| | | | | | | | |

Was this topic helpful?