Character arrays and string arrays provide storage for text data in MATLAB®.
A character array is a sequence of characters, just as a
numeric array is a sequence of numbers. A typical use is to
store short pieces of text as character
vectors, such as c = 'Hello
World'
.
A string array is a container for pieces of text. String
arrays provide a set of functions for working with text as data.
Starting in R2017a, you can create strings using double quotes,
such as str = "Greetings friend"
. To convert
data to string arrays, use the string
function.
For more information, see Text in String and Character Arrays or watch Using String Arrays for Text Data.
Text in String and Character Arrays
Store and manipulate text using either string arrays or character arrays.
Analyze Text Data with String Arrays
This example shows how to analyze text data with string arrays. It shows how to store, split, and sort text, and how to compute and collect statistics for text in a string array.
Compose character arrays or string arrays that include ordinary text and data formatted to your specification.
MATLAB provides several functions to search for, replace, or extract text in string arrays and character vectors.
MATLAB stores all characters as Unicode characters. Both strings and character vectors use the same encoding. You can convert characters to their Unicode code values, and numbers to characters.
Specify hexadecimal and binary values either as literals or as text. Hexadecimal and binary literals are stored as integers. You can convert text representing hexadecimal and binary values to numbers, and numbers to text representations.