Convert to cell array of character vectors
C = cellstr( converts
S to a cell array.
S is a character array, then
each row of
S is a cell of
Any trailing whitespace characters in the rows of
removed, except for significant whitespace such as nonbreaking space
characters. Use the
char function to convert back
into a character array.
S is a cell array of character
S is a categorical array, then
a cell array of the same size.
S = cellstr( converts
a datetime, duration, or calendar duration array into a cell array
of character vectors in the format specified by the
D. The output has the same dimensions as
Create a character array. Include trailing spaces so that each row has the same length, resulting in a 3-by-4 array.
S = ['abc ';'defg';'hi ']
S = abc defg hi
Name Size Bytes Class Attributes S 3x4 24 char
Convert the character array to a 3-by-1 cell array of character vectors.
C = cellstr(S)
C = 'abc' 'defg' 'hi'
Name Size Bytes Class Attributes C 3x1 354 cell
D = calmonths(15:17) + caldays(8) + hours(1.2345)
D = 1y 3mo 8d 1h 14m 4.2s 1y 4mo 8d 1h 14m 4.2s 1y 5mo 8d 1h 14m 4.2s
Convert the array to a cell array of character vectors.
C = cellstr(D)
C = '1y 3mo 8d 1h 14m ...' '1y 4mo 8d 1h 14m ...' '1y 5mo 8d 1h 14m ...'
Name Size Bytes Class Attributes C 1x3 462 cell
S— Input arraycharacter array | cell array of character vectors | categorical array
Input array, specified as a character array, a cell array of character vectors, or a categorical array.
S is a character array, then each row
S becomes a separate cell of
with trailing spaces removed.
cellstr does not
remove trailing spaces that are nonbreaking space characters.
S is a cell array of character vectors,
D— Input date and timedate or duration array
Input date and time, specified as a date or duration array.
fmt— Date and time format
(default) | character vector
Date and time format, specified as a character vector. The supported
formats depend on the data type of input
datetime formats can include combinations
of units and delimiters, such as
For details, see the
Format property for datetime arrays.
duration formats are either single
's') or one of these combinations:
Any of the above, with up to nine
to indicate fractional second digits, such as
calendarDuration formats can include
combinations of the characters
't' in order from largest to smallest unit
of time, such as
For more information on the
see Set Date and Time Display Format.
locale— Locale of the character vectors to createcharacter vector
Locale of the character vectors to create, specified as a character vector.
locale can be:
'system', to specify your system
a character vector in the form
xx is a lowercase ISO 639-1 two-letter
code that specifies a language, and
an uppercase ISO 3166-1 alpha-2 code that specifies a country.
These are the same character vectors accepted by the
pair argument for the
datetime function. The locale
affects the language used in the output array.
cellstr does not remove trailing whitespace
characters from character arrays when the characters are significant
whitespace, such as nonbreaking space characters.
This table shows the most common characters that are significant whitespace characters and their descriptions. For more information, see Whitespace character.
Significant Whitespace Character
Narrow no-break space