MATLAB: Cell 2 3d matrix

cell to 3d matrix

Hej, I have a cell [1×25] of [256×256 int16] I would like to convert cell into a 3d matrix [256x256x25] (create a stack) but if i using cell2mat I obtain a [256×6400] matrix. Could anyone halp me?

Best Answer

Use CAT and comma-separated list expansion:
sz = [2 3] ; % arbitray size
C = {rand(sz), ones(sz), zeros(sz)} % example of your cell data (all elements the same size!)
M = cat(3,C{:}) % concatenate in the 3rd dimension