# Documentation

### This is machine translation

Translated by
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

## Cell Arrays of Character Vectors

### Convert to Cell Array of Character Vectors

When you create character arrays from character vectors, all of the vectors must have the same length. This often means that you have to pad blanks at the end of character vectors to equalize their length. However, another type of MATLAB® array, the cell array, can hold different sizes and types of data in an array without padding. A cell array of character vectors is a cell array where every cell contains a character vector. Cell arrays of character vectors provide a flexible way to store character vectors of varying lengths.

Convert a character array to a cell array of character vectors. `data` is padded with spaces so that each row has an equal number of characters. Use `cellstr` to convert the character array.

```data = ['Allison Jones';'Development ';'Phoenix ']; celldata = cellstr(data) ```
```celldata = 3×1 cell array {'Allison Jones'} {'Development' } {'Phoenix' } ```

`data` is a `3`-by-`13` character array, while `celldata` is a `3`-by-`1` cell array of character vectors. `cellstr` also strips the blank spaces at the ends of the rows of `data`.

The `iscellstr` function determines if the input argument is a cell array of character vectors. It returns a logical `1` (`true`) in the case of `celldata`:

```iscellstr(celldata) ```
```ans = logical 1 ```

Use `char` to convert back to a padded character array.

```chr = char(celldata) ```
```chr = 3×13 char array 'Allison Jones' 'Development ' 'Phoenix ' ```

For more information on cell arrays, see Access Data in Cell Array.

While the phrase "cell array of strings" frequently has been used to describe such arrays, the phrase is not accurate because such a cell array holds character vectors, not strings. Starting in R2016b, MATLAB provides string arrays as another means of storing text. If you create variables that have the `string` data type, store them in string arrays, not cell arrays.

### Functions for Cell Arrays of Character Vectors

This table describes the MATLAB functions for working with cell arrays of character vectors.

Function

Description

`cellstr`

Convert a character array to a cell array of character vectors.

`char`

Convert a cell array of character vectors to a character array.

`deblank`

Remove trailing blanks from a character array.

`iscellstr`

Return `true` for a cell array of character arrays.

`sort`

Sort elements in ascending or descending order.

`strcat`

Concatenate character arrays or cell arrays of character arrays.

`strcmp`

Compare character arrays or cell arrays of character arrays.

You can also use the following `set` functions with cell arrays of character vectors.

Function

Description

`intersect`

Set the intersection of two vectors.

`ismember`

Detect members of a set.

`setdiff`

Return the set difference of two vectors.

`setxor`

Set the exclusive OR of two vectors.

`union`

Set the union of two vectors.

`unique`

Set the unique elements of a vector.

Was this topic helpful?

#### Beyond Excel: The Manager's Guide to Solving the Big Data Conundrum

Download white paper