# Cell Array Reshape Operation

7 visualizaciones (últimos 30 días)
MarshallSc el 18 de En. de 2022
Editada: MarshallSc el 19 de En. de 2022
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!
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

DGM el 19 de En. de 2022
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
##### 1 comentarioMostrar -1 comentarios más antiguosOcultar -1 comentarios más antiguos
MarshallSc el 19 de En. de 2022
Thanks a lot mate!

Iniciar sesión para comentar.

### Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

### Community Treasure Hunt

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

Start Hunting!

Translated by