Cell array of matrices to multi-dim matrix

1 次查看(过去 30 天)
I have a multi-dimensional cell array C of dimensions c1 x c2 x... x ck.
Each cell contains a multi-dimensional matrix of identical dimensions m1 x m2 x ... x mj
I want to transform that cell array into a matrix A of dimensions c1 x c2 x... x ck x m1 x m2 x ... x mj
such that A(i1, i2,..., ik, :, :,..., :)=C{i1,i2,...,ik}
The number of dimensions as well as the number of elements along each dimension can change, so I cannot assume a fixed k or j.
Is that feasible? Thanks in advance for any hint.

回答(2 个)

Walter Roberson
Walter Roberson 2021-7-31
k = randi([3 6], 1)
k = 5
j = randi([3 6], 1)
j = 5
c = randi([3 6], 1, k)
c = 1×5
6 3 6 4 4
m = randi([2 5], 1, j)
m = 1×5
5 5 4 2 3
C = cell(c);
C = cellfun(@(~) randi(9, m), C, 'uniform', 0)
C = 5-D cell array
C(:,:,1,1,1) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,2,1,1) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,3,1,1) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,4,1,1) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,5,1,1) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,6,1,1) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,1,2,1) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,2,2,1) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,3,2,1) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,4,2,1) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,5,2,1) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,6,2,1) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,1,3,1) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,2,3,1) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,3,3,1) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,4,3,1) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,5,3,1) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,6,3,1) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,1,4,1) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,2,4,1) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,3,4,1) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,4,4,1) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,5,4,1) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,6,4,1) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,1,1,2) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,2,1,2) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,3,1,2) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,4,1,2) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,5,1,2) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,6,1,2) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,1,2,2) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,2,2,2) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,3,2,2) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,4,2,2) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,5,2,2) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,6,2,2) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,1,3,2) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,2,3,2) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,3,3,2) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,4,3,2) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,5,3,2) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,6,3,2) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,1,4,2) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,2,4,2) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,3,4,2) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,4,4,2) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,5,4,2) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,6,4,2) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,1,1,3) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,2,1,3) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,3,1,3) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,4,1,3) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,5,1,3) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,6,1,3) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,1,2,3) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,2,2,3) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,3,2,3) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,4,2,3) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,5,2,3) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,6,2,3) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,1,3,3) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,2,3,3) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,3,3,3) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,4,3,3) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,5,3,3) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,6,3,3) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,1,4,3) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,2,4,3) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,3,4,3) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,4,4,3) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,5,4,3) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,6,4,3) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,1,1,4) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,2,1,4) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,3,1,4) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,4,1,4) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,5,1,4) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,6,1,4) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,1,2,4) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,2,2,4) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,3,2,4) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,4,2,4) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,5,2,4) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,6,2,4) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,1,3,4) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,2,3,4) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,3,3,4) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,4,3,4) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,5,3,4) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,6,3,4) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,1,4,4) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,2,4,4) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,3,4,4) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,4,4,4) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,5,4,4) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} C(:,:,6,4,4) = {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double} {5-D double}
size(C)
ans = 1×5
6 3 6 4 4
size(C{1})
ans = 1×5
5 5 4 2 3
A = reshape(cat(k+1, C{:}), [c m]);
size(A)
ans = 1×10
6 3 6 4 4 5 5 4 2 3
  1 个评论
Lionel Pöffel
Lionel Pöffel 2021-8-2
Hi Walter,
thank you for your answer. It looked like something that could work. But I tested it, and what I got was the following:
B(1:2,1:2)={[]};
B(1,1)={[1 2; 3 4]};
B(1,2)={[0.5 0.7; 0.2 0.3]};
B(2,2)={[5.5 5.7; 5.2 5.3]};
B(2,1)={[34 52; 541 64]}
B =
2×2 cell array
{2×2 double} {2×2 double}
{2×2 double} {2×2 double}
A = reshape(cat(3, B{:}), [2 2 2 2]);
squeeze(A(1,1,:,:))
ans =
1.0000 0.5000
34.0000 5.5000
B{1,1}
ans =
1 2
3 4
So it seems like either I'm somehow applying your aaproach incorrectly, or it arranges the matrix elements in some unexpected way.
Any thoughts? thanks in advance

请先登录,再进行评论。


Lionel Pöffel
Lionel Pöffel 2021-8-2
By now I worked out something that does what I want, albeit not in the most elegant way:
function [M,success] = CopyMultDimMatCell2MultDimMat(C)
%cell array C can have arbitrary dimensions c1 x c2 x... x ck.
%Each cell contains a multi-dimensional matrix of identical dimensions m1 x m2 x ... x mj
%the function transforms C into a matrix M of dimensions c1 x c2 x... x ck x m1 x m2 x ... x mj
%such that squeeze(M(i1, i2,..., ik, :, :,..., :))=C{i1,i2,...,ik}
%assum success initially
success=true;
%remove unnecessary dimensions
B=squeeze(C);
%acquire dimensions of cell array
cdim=size(B);
numcdim=max(size(cdim));%get number of dimensions
%acquire dimensions of one matrix in the cell to check identical
%dimensionalitdy across the cell
Ndim=size(squeeze(B{1}));
numNdim=max(size(Ndim));%get number of dimensions
%check dimensionality for all matrices in B
for i=2:numel(B)
Comparator=size(squeeze(B{i}));
CompRes=Ndim~=Comparator;
if sum(CompRes,'all')>0
success=false;
end
end
if success
%pre-dimensioning
M=zeros([cdim Ndim]);
for i=1:numel(M)
%copy all the entries in the right place
%unfortunately, Matlab-internal fancy functions like cat
% and re-shape always want the individual matrix in the initial dimensions.
% But for code-gen to be efficient, we need the initial dimensions
% for variant indexing
%get subscripts for the big matrix
[Inds{1:(numcdim+numNdim)}]=ind2sub([cdim Ndim],i);
%get the subscripts that belong to indexing B
CInds=Inds(1:numcdim);
%get individual matrix
SubMatAtI=B{CInds{:}};
%get some indexing array with "free range" for the last dimensions
IndsSubMat=Inds;
IndsSubMat( (numcdim+1) : (numcdim+numNdim) )={':'};
%copy the matrix from one cell into the "free range"
M(IndsSubMat{:})=SubMatAtI;
end
end
end
I hope that makes sense.

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by