Programming and Data Types    

Character Arrays

In MATLAB, the term string refers to an array of characters. MATLAB represents each character internally as its corresponding numeric value. Unless you want to access these values, however, you can simply work with the characters as they display on screen.

This section covers:

Creating Character Arrays

Specify character data by placing characters inside a pair of single quotes. For example, this line creates a 1-by-13 character array called name.

In the workspace, the output of whos shows

You can see that a character uses two bytes of storage internally.

The class and ischar functions show name's identity as a character array.

You can also join two or more character arrays together to create a new character array. Use either the string concatenation function, strcat, or the MATLAB concatenation operator, [], to do this. The latter preserves any trailing spaces found in the input arrays.

You can also concatenate strings vertically with strvcat.

  Function Summary Creating Two-Dimensional Character Arrays