Search code examples
matlabconcatenationcell-array

Concatenate multiple cells


I have a cell called Object that contains 1x24 cells which all have 1 column but have the number of rows ranging from 14 to 16. Some cells, however, are empty. I would like to concatenate these cell into one single cell P with the dimension of 16 x 24. This is what I have tried:

for z=1:24
Summary.P{z}=cat(2,Object{1,z});
end

However, this gives me the error: Cell contents assignment to non-cell array object. Is this because I have the empty cells? Ideally, I'd like to get rid of the empty cells before concatenating.

Could anyone please help me?

Thanks!

P.S. If the different numbers of rows are an issue, I could just use the first 14 rows of each cell. This will make all the non-empty cells even in terms of the number of rows.


Solution

  • The initial error is most likely that either Summary.P is initialized and not as a cell or that Object is not a cell. The error means that you tries to access a cell element in a non-cell type. Ohter than that, the lines you run will give you a clone of Object. Third, are you trying to create 1 cell with a 16x24 matrix inside, you need to make sure that the dimensions are consistent. If they are use

    Summary.P = {cell2mat(Object)}