Question

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?

Was it helpful?

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]

OTHER TIPS

If it consists of numbers only, try this -

num2cell(cell2mat(cellarray))

Basic idea here is to get all of the data into a double matrix and then convert each of it's elements into elements of a cell array.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top