Cell Array Reshape Operation

7 次查看(过去 30 天)
I have this 10x10 cell array:
I want to reshape it into a 4x4 cell each containing a 10x10 matrix keeping the order of each value in the matrices. For example, the first new cell ( cell(1,1) ) contains the first values of the 16x1 matrices which will transform into a 10x10 for each cell and so on. I'd appreciate it if someone can please help me! Thank you!

采纳的回答

DGM
DGM 2022-1-19
There are probably other ways, but...
% a patterned test array
A = repmat({(1:16).', (17:32).'; (33:48).', (49:64).'},5,5)
A = 10×10 cell array
{16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double} {16×1 double}
B = cell2mat(A(:).');
B = reshape(permute(B,[2 3 1]),10,10,[]);
B = reshape(num2cell(B,[1 2]),4,4)
B = 4×4 cell array
{10×10 double} {10×10 double} {10×10 double} {10×10 double} {10×10 double} {10×10 double} {10×10 double} {10×10 double} {10×10 double} {10×10 double} {10×10 double} {10×10 double} {10×10 double} {10×10 double} {10×10 double} {10×10 double}
% inspect the result
B{1}
ans = 10×10
1 17 1 17 1 17 1 17 1 17 33 49 33 49 33 49 33 49 33 49 1 17 1 17 1 17 1 17 1 17 33 49 33 49 33 49 33 49 33 49 1 17 1 17 1 17 1 17 1 17 33 49 33 49 33 49 33 49 33 49 1 17 1 17 1 17 1 17 1 17 33 49 33 49 33 49 33 49 33 49 1 17 1 17 1 17 1 17 1 17 33 49 33 49 33 49 33 49 33 49
B{2}
ans = 10×10
2 18 2 18 2 18 2 18 2 18 34 50 34 50 34 50 34 50 34 50 2 18 2 18 2 18 2 18 2 18 34 50 34 50 34 50 34 50 34 50 2 18 2 18 2 18 2 18 2 18 34 50 34 50 34 50 34 50 34 50 2 18 2 18 2 18 2 18 2 18 34 50 34 50 34 50 34 50 34 50 2 18 2 18 2 18 2 18 2 18 34 50 34 50 34 50 34 50 34 50

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by