Create Rectangular Character Array

Character arrays are m-by-n arrays
of characters, where m is not always 1.
You can join two or more character vectors together to create a character
array. This is called concatenation and is
explained for numeric arrays in the section Concatenating Matrices.
As with numeric arrays, you can combine character arrays vertically
or horizontally to create a new character array.

Alternatively, combine character vectors into a cell array.
Cell arrays are flexible containers that allow you to easily combine
character vectors of varying length.

Combine Character Vectors Vertically

To combine character vectors into a two-dimensional character
array, use square brackets or the char function.

Apply the MATLAB® concatenation operator, [].
Separate each row with a semicolon (;). Each row
must contain the same number of characters. For example, combine three
character vectors of equal length:

devTitle = ['Thomas R. Lee'; ...'Sr. Developer'; ...'SFTware Corp.'];

If the character vectors have different lengths, pad with space
characters as needed. For example:

Expand Character Arrays

Generally, MathWorks® does not recommend expanding
the size of an existing character array by assigning additional characters
to indices beyond the bounds of the array such that part of the array
becomes padded with zeros.

Was this topic helpful?

Select Your Country

Choose your country to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .