Documentation

This is machine translation

Translated by Microsoft
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.

Combine Cell Arrays

This example shows how to combine cell arrays by concatenation or nesting. To run the code in this example, create several cell arrays with the same number of columns:

C1 = {1, 2, 3};
C2 = {'A', 'B', 'C'};
C3 = {10, 20, 30};

Concatenate cell arrays with the array concatenation operator, []. In this example, vertically concatenate the cell arrays by separating them with semicolons:

C4 = [C1; C2; C3]

C4 is a 3-by-3 cell array:

C4 = 
    [ 1]    [ 2]    [ 3]
    'A'     'B'     'C' 
    [10]    [20]    [30]

Create a nested cell array with the cell array construction operator, {}:

C5 = {C1; C2; C3}

C5 is a 3-by-1 cell array, where each cell contains a cell array:

C5 = 
    {1x3 cell}
    {1x3 cell}
    {1x3 cell}

For more information, see Concatenating Matrices. To combine cell arrays of character vectors into one character vector, use the strjoin function.

Was this topic helpful?