Search code examples
arraysmatlabcell-array

Matlab convert consistently sized cells to one matrix


I have a [100×1] cell looking like:

{1x5 cell}
{1x5 cell}
{1x5 cell}
{1x5 cell}
...
{1x5 cell}

I would like to obtain instead a [100×5] cell. How do I do that in MATLAB?


Solution

  • In the general case (contents are not necessarily numbers):

    result = vertcat(c{:});
    

    Example:

    >> c = {{'a',1}; {'aa','b'}; {3,2}}
    c = 
        {1x2 cell}
        {1x2 cell}
        {1x2 cell}
    >> result = vertcat(c{:})
    result = 
        'a'     [1]
        'aa'    'b'
        [ 3]    [2]