Concatenation of 4x8 cell arrays

My CellArray looks like this,
Columns 1 through 4
[] [4x32 double] [4x2511 double] [4x1874 double]
[4x841 double] [4x1810 double] [4x2269 double] [4x4312 double]
[] [4x256 double] [4x841 double] [4x1101 double]
[] [] [] []
Columns 5 through 8
[4x1586 double] [4x792 double] [] [4x1 double]
[4x3861 double] [4x1607 double] [4x878 double] [4x790 double]
[4x885 double] [4x1049 double] [4x297 double] [4x6 double]
[] [] [] []
[4x1586 double] [4x792 double] [] [4x1 double]
[4x3861 double] [4x1607 double] [4x878 double] [4x790 double]
[4x885 double] [4x1049 double] [4x297 double] [4x6 double]
[] [] [] []
Now I have to concatenate the cells leaving out the empty cells and the result should be 4x double in one cell.Please help me out.I am very much new to matlab. Thanks in advance..

 Accepted Answer

Hi,
try
cell2mat(your_cell_variable)
So a small example would be
a{1,1} = rand(4,10);
a{1,2} = [];
a{2,1} = [];
a{2,2} = rand(4,100)
b = cell2mat(a);
dim = size(b)
which leads to
a =
[4x10 double] []
[] [4x100 double]
dim =
4 110

3 Comments

hi Friedrich,
Thanx for your valuable reply.
Its working with above example but if i am taking for 4x8 its giving me error,
the example I have tried is,
a{1,1} =[] ;
a{1,2} = rand(4,32);
a{1,3} = rand(4,2511);
a{1,4} = rand(4,1874);
a{1,5} = rand(4,1586);
a{1,6} = rand(4,792);
a{1,7} = [];
a{1,8} = rand(4,1);
a{2,1} = rand(4,841);
a{2,2} = rand(4,1810);
a{2,3} = rand(4,2269);
a{2,4} = rand(4,4312);
a{2,5} = rand(4,3861);
a{2,6} = rand(4,1607);
a{2,7} = rand(4,878);
a{2,8} = rand(4,790);
a{3,1} = [];
a{3,2} = rand(4,256);
a{3,3} = rand(4,841);
a{3,4} = rand(4,1101);
a{3,5} = rand(4,885);
a{3,6} = rand(4,1049);
a{3,7} = rand(4,297);
a{3,8} = rand(4,6);
a{4,1} =[] ;
a{4,2} =[];
a{4,3} =[] ;
a{4,4} =[] ;
a{4,5} =[] ;
a{4,6} =[] ;
a{4,7} =[] ;
a{4,8} =[] ;
b = cell2mat(a);
the error is,
CAT arguments dimensions are not consistent.
Error in ==> cell2mat at 84
m = cat(1,m{:});
Error in ==> Untitled99 at 50
b = cell2mat(a);
What should be done to get rid of this issue.
Okay in that case use:
b = cell2mat(reshape(a,1,32));
Thanx a lot its working ..
greets,
Manros

Sign in to comment.

More Answers (0)

Categories

Asked:

on 30 Dec 2011

Community Treasure Hunt

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

Start Hunting!