0
0
0
0
0
0
1
0
str{2,2}(TF) = "-";
str(2,2)
ans =
"Skylab-B"
Note that in this case, you can also replace spaces using the replace function, without resorting to
curly brace indexing.
replace(str(2,2)," ","-")
ans =
"Skylab-B"
Concatenate Strings into String Array
Concatenate strings into a string array just as you would concatenate arrays of any other kind.
Concatenate two string arrays using square brackets, [].
str1 = ["Mercury","Gemini","Apollo"];
str2 = ["Skylab","Skylab B","ISS"];
str = [str1 str2]
str = 1x6 string
"Mercury"
"Gemini"
"Apollo"
"Skylab"
"Skylab B"
"ISS"
Transpose str1 and str2. Concatenate them and then vertically concatenate column headings onto
the string array. When you concatenate character vectors into a string array, the character vectors
are automatically converted to strings.
str1 = str1';
str2 = str2';
str = [str1 str2];
str = [["Mission:","Station:"] ; str]
str = 4x2 string
"Mission:"
"Station:"
"Mercury"
"Skylab"
"Gemini"
"Skylab B"
"Apollo"
"ISS"
Append Text to Strings
To append text to strings, use the plus operator, +. The plus operator appends text to strings but
does not change the size of a string array.
Append a last name to an array of names. If you append a character vector to strings, then the
character vector is automatically converted to a string.
names = ["Mary";"John";"Elizabeth";"Paul";"Ann"];
names = names + ' Smith'
names = 5x1 string
"Mary Smith"
Create String Arrays
6-9
0
0
0
0
0
1
0
str{2,2}(TF) = "-";
str(2,2)
ans =
"Skylab-B"
Note that in this case, you can also replace spaces using the replace function, without resorting to
curly brace indexing.
replace(str(2,2)," ","-")
ans =
"Skylab-B"
Concatenate Strings into String Array
Concatenate strings into a string array just as you would concatenate arrays of any other kind.
Concatenate two string arrays using square brackets, [].
str1 = ["Mercury","Gemini","Apollo"];
str2 = ["Skylab","Skylab B","ISS"];
str = [str1 str2]
str = 1x6 string
"Mercury"
"Gemini"
"Apollo"
"Skylab"
"Skylab B"
"ISS"
Transpose str1 and str2. Concatenate them and then vertically concatenate column headings onto
the string array. When you concatenate character vectors into a string array, the character vectors
are automatically converted to strings.
str1 = str1';
str2 = str2';
str = [str1 str2];
str = [["Mission:","Station:"] ; str]
str = 4x2 string
"Mission:"
"Station:"
"Mercury"
"Skylab"
"Gemini"
"Skylab B"
"Apollo"
"ISS"
Append Text to Strings
To append text to strings, use the plus operator, +. The plus operator appends text to strings but
does not change the size of a string array.
Append a last name to an array of names. If you append a character vector to strings, then the
character vector is automatically converted to a string.
names = ["Mary";"John";"Elizabeth";"Paul";"Ann"];
names = names + ' Smith'
names = 5x1 string
"Mary Smith"
Create String Arrays
6-9
