combining cell arrarys to one cell

I have a cell array containing a number (say n) of 1x4 cells. I want to combine them in one cell to obtain a cell of nx4 cells. please let me know the solution.
Thanks all.

 Accepted Answer

I think you want to concatenate the n cells into a simple n-by-4 array, like this
C = {[1 2 3 4],[2 3 4 5],[4 3 2 1]} % n=3 cells, each holding a 1-by-4 array
M = cat(1,C{:}) a n=3-by-4 array

6 Comments

And if you want to turn this into a single 1-by-1 cell array, {M} would do, but I do not recommend this ...
The cell array C contains 3 double vectors rather than 3 cells.
class(C{1})
ans =
'double'
@ Jos and Adam, you are close to my point, i am trying get a single array holding 3 by 4 cells, how can I do that ?
Could you provide a short, precise example of what your data look like before the transformation and what you want it to look like after the transformation?
Thanks, Josand Adam, your help worked, only for Adam's case there was an unncessary space whigh resuted into an error. Have a good day guys !!
Where was there an unnecessary space? Your line that worked is identical to my suggestion.

Sign in to comment.

More Answers (1)

Adam Danz
Adam Danz on 27 Sep 2018
Edited: Adam Danz on 27 Sep 2018
Here's a demo using fake data.
t = {{1:4}',{1:4}',{1:4}'}; %also works if t is columnar
m = cell2mat([t{:}]')
m =
1 2 3 4
1 2 3 4
1 2 3 4

2 Comments

carl hooper
carl hooper on 27 Sep 2018
Edited: carl hooper on 27 Sep 2018
Thanks, I copied your lines but An error comes up showing unexpected matlab operator. I got the correct one as
cell2mat([t{:}]');
That's identical to my 2nd line. The first line in my response is just producing fake data. Glad it worked!

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!