MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1

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}

To combine cell arrays of character vectors into one character vector, use the strjoin
function.

See Also
strjoin

Related Examples



  • “Creating, Concatenating, and Expanding Matrices”


12 Cell Arrays

Free download pdf