string
Creates a string array, converting text, numbers and other values.
Category: Language Fundamentals > Data Types
Syntax
s = string(A)
Converts A to a string array of the same size.
Description
Strings are the modern text type: each element holds a whole piece of text of any length, so no padding is needed and arrays of text are indexed like numeric arrays. They use double quotes in literals, "like this", and + concatenates them.
Numbers are converted with the same rules as num2str with about 5 significant digits; string(pi) gives "3.1416". Missing values are written <missing>.
Input arguments
A- Character vector, cell array of character vectors, number, logical, datetime, duration, categorical or other convertible value.
Output arguments
s- String array. A character vector becomes one string; a numeric array becomes one string per element.
Example
From characters and numbers
s = string('hello')
t = string([1 2.5 3])
string("a") + "b"
strlength(s)
Output
s = "hello"
t = 1×3 string array
"1" "2.5" "3"
ans = "ab"
ans = 5