Convert cell arrays to 4-D array
12 views (last 30 days)
Show older comments

I've got a 35*10 cell array, which contains multiple matrices with the same size(256*256). I want to convert it into a 4-D array(256*256*10*35).
1 Comment
Accepted Answer
Matt J
on 22 Apr 2019
Edited: Matt J
on 23 Apr 2019
Where C is your cell array:
M = reshape( cat(3,C{:}) , [256,256,10,35])
EDIT:
Or M = reshape( cat(3,C{:}) , [256,256,35,10]) ?
4 Comments
Matt J
on 23 Apr 2019
Edited: Matt J
on 23 Apr 2019
OK, I think you should allow for the possibility, though, that the OP had a typo and really meant to say that the final dimensions should be [256,256,35,10], since that requires the least data reorganization. In that case, my solution is valid with the following small change.
M = reshape( cat(3,C{:}) , [256,256,35,10])
It is also possible that the OP meant a 3rd alternative,
C=C.';
M = reshape( cat(3,C{:}) , [256,256,10,35])
See Also
Categories
Find more on Matrices and Arrays 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!