Opening the book…
A string is a sequence of characters placed between double quotation marks. In MATLAB, a single piece of text stored as a string is often called a string scalar. For example to create the phrase Hello Worldwe enclose the phrase in double quotation marks.
myString = "Hello World"
The variable myString stores the text Hello World as a string. The space between Hello and World counts as a character too.
String Arrays
Just like we can create arrays of numbers, we can create arrays of strings. Each element of the array is a string. The following example creates a 2-by-2 string array.
strArray = ["Mercury", "Jupiter"; "Earth", "Saturn"]
The first row contains "Mercury" and "Jupiter". The second row contains "Earth" and "Saturn".
We can index a string array the same way we index other MATLAB arrays.
secondRow = strArray(2, :)
The result is a 1-by-2 string array containing the strings from the second row.
This page titled 7.3: Creating Strings was last modified on Tue, 30 Jun 2026 02:11:53 GMT and is shared under a CC BY-NC-SA license and was authored, remixed, and/or curated by Zara Noroozi.
The book could not be loaded just now.