How to concatenate cells within cells
1 view (last 30 days)
Show older comments
Say I have X={{1},{2},{3},{4}}, Y={{5},{6},{7;8},{9;10}}
I would like to have Z={{1;5},{2;6},{3;7;8},{4;9;10}},
that is, concatenate X over Y, both 1x4 cell arrays, into Z which is also a 1x4 cell array.
Is there a simple way to do this?
0 Comments
Accepted Answer
Stephen23
on 12 May 2023
Edited: Stephen23
on 12 May 2023
"Is there a simple way to do this?"
Yes, CELLFUN and VERTCAT:
X = {{1},{2},{3},{4}};
Y = {{5},{6},{7;8},{9;10}};
Z = cellfun(@vertcat,X,Y,'uni',0)
Checking:
Z{:}
Note that storing numeric data in those nested cell arrays is not efficient data design. Simpler numeric arrays are intended for storing numeric data.
More Answers (0)
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!