Convert cell array of cell arrays to matrix of matrices

后端 未结 5 1362
一向
一向 2021-01-05 05:37

I can convert a cell array of matrices to matrix:

>> C={[1,1]; [2,2]; [3,3]};
>> cell2mat(C)
ans =
     1     1
     2     2
     3     3
         


        
5条回答
  •  旧时难觅i
    2021-01-05 06:03

    Okay, the question is a long time ago - but maybe my answer might help other readers or searchers.
    I think the best solution is nearly the idea presented by Eitan T but it is possible to do that without reshaping. For me

    C={{1,1;1,1};{2,2;2,2};{3,3;3,3}};
    A=cell2mat(cat(3,C{:}))
    

    does what was asked for - thus answers with

    A(:,:,1) =
         1     1
         1     1
    A(:,:,2) =
         2     2
         2     2
    A(:,:,3) =
         3     3
         3     3
    

    Hoping that helps.

提交回复
热议问题