Search code examples
matlabmatrix3dreshapepermute

Reshape mxn cell array to mxnxt 3D matrix in Matlab


I looked through past answers but I could find one that gave me a definitive answer for my case (weird as it seems simple).

I have a mxn cell array with each having a tx1 matrix and I would like to reshape this to a mxnxt 3D matrix. I saw a few example with permute and remat but did not get my answer there.

Thanks!


Solution

  • You just need cell2mat with a little of permute:

    c = repmat({(1:4).'},2,3); %'// example cell array
    result = permute(cell2mat(permute(c,[3 1 2])), [2 3 1])