Splitting n by 1 matrix

1 vue (au cours des 30 derniers jours)
okoth ochola
okoth ochola le 18 Juil 2022
Modifié(e) : Stephen23 le 18 Juil 2022
Hi, I have n by 1 matrix, I want to splitt this matrix into systematically into several smaller matrices of the same dimension. For example let A=transpose([1:1:12552), I want to make other matrices of (24 by 1) from the A. Is there a short command I can use? I have tried 'mat2cell' function but it returns error. Is there something am missing?

Réponse acceptée

Stephen23
Stephen23 le 18 Juil 2022
Modifié(e) : Stephen23 le 18 Juil 2022
A = transpose(1:12552);
C = num2cell(reshape(A,24,[]),1)
C = 1×523 cell array
{24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double} {24×1 double}
You can eaily access the content of the cell array C using indexing, e.g. the second cell:
C{2}
ans = 24×1
25 26 27 28 29 30 31 32 33 34
  4 commentaires
okoth ochola
okoth ochola le 18 Juil 2022
It worked, thank you so much
Stephen23
Stephen23 le 18 Juil 2022
Modifié(e) : Stephen23 le 18 Juil 2022
" Is there a fucntion that I can use to calculate mean of each submatrix within C, so as to end up with 523 by 1 matrix?"
The simple and efficient MATLAB approach would avoid the cell array:
A = transpose(1:12552);
B = mean(reshape(A,24,[]),1).'
B = 523×1
12.5000 36.5000 60.5000 84.5000 108.5000 132.5000 156.5000 180.5000 204.5000 228.5000

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Resizing and Reshaping Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by