char
Converts numbers to characters, or text of several kinds to a char array.
Category: Language Fundamentals > Data Types
Syntax
c = char(n)
Converts character codes to characters.
c = char(C)
Converts a cell array of text to a padded char matrix, one row per cell.
c = char(S)
Converts a string array to a char array.
Description
For numeric input char(65) is 'A' and char(65:70) is 'ABCDEF'; the inverse is double('A'). Codes above 255 give Unicode characters.
For several pieces of text, char builds a rectangular matrix by padding each row with blanks on the right, so char({'a','bcd'}) is a 2-by-3 matrix. This matrix can be turned back into a cell array of words with cellstr.
Input arguments
n- Numeric array of character codes (nonnegative integers).
C- Cell array of character vectors or strings.
S- String array.
Output arguments
c- Char array. Shorter rows are padded with blanks to the length of the longest.
Example
Codes and words
char(72:76)
char({'a','bcd'})
double('A')
Output
ans = 'HIJKL'
ans = 2×3 char array
'a '
'bcd'
ans = 65