How to convert a cell array of cell arrays to matrix ?

I need to convert a cell array of cell arrays to matrix. I tried to use cell2mat() , but I am getting an error message.
C={{1 3 4};{1 3 3}}
C =
{1x3 cell}
{1x3 cell}
cell2mat(C)
Error using cell2mat (line 53)
Cannot support cell arrays containing cell arrays or objects.

 Accepted Answer

C={{1 3 4};{1 3 3}}
out=cell2mat(cellfun(@(x) cell2mat(x),C,'un',0))

3 Comments

Thanks @Azzi, but when i use the above command for a larger cell array, i am getting an error,
Cell contents reference from a non-cell array object.
Error in cell2mat (line 43) cellclass = class(c{1});
Can u say, what this error means? Thanks in advance.
This has nothing to do with the fact that tour cell array is bigger. Your example is not representative of your data. Please give more details about your cells.
Maybe your cell array looks like
C={{1 3 4};{1 3 3};[1 2 3]}
The third element is not a cell array

Sign in to comment.

More Answers (1)

With different type of objects in the array, you cant use the lambda as suggested above!

Categories

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!