convertCharsToStrings
Converts character vectors to strings, leaving other values alone.
Category: Language Fundamentals > Data Types
Syntax
B = convertCharsToStrings(A)
Returns A with character vectors replaced by strings.
Description
The function exists to make code accept both kinds of text. A char vector becomes a 1-by-1 string, and a cell array of char vectors becomes a string array. Values that are already strings or are not text are returned unchanged.
The opposite conversion is convertStringsToChars.
Input arguments
A- A char vector, or a cell array of char vectors.
Output arguments
B- A string scalar, or a string array of the same size as the cell array.
Example
Chars to strings
convertCharsToStrings('abc')
convertCharsToStrings({'a','b'})
Output
ans = "abc"
ans = 1×2 string array
"a" "b"
See also
convertStringsToChars convertContainedStringsToChars string cellstr