Splitting n by 1 matrix

1 view (last 30 days)
okoth ochola
okoth ochola on 18 Jul 2022
Edited: Stephen23 on 18 Jul 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?

Accepted Answer

Stephen23
Stephen23 on 18 Jul 2022
Edited: Stephen23 on 18 Jul 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 Comments
okoth ochola
okoth ochola on 18 Jul 2022
It worked, thank you so much
Stephen23
Stephen23 on 18 Jul 2022
Edited: Stephen23 on 18 Jul 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

Sign in to comment.

More Answers (0)

Categories

Find more on Resizing and Reshaping Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!