Split Matrix into multiple Submatrices

15 views (last 30 days)
I have a large matrix of 6000x10 arrays. I wanted to get some thing like 100 different 60x10 matrices. How can I do that? I can think of a method of cell2mat, in case I do that will I be able to add rows/columns in those cells?

Accepted Answer

Walter Roberson
Walter Roberson on 12 Aug 2021
YourArray = randi(9, 6000, 10);
subarrays = mat2cell(YourArray, 60*ones(1,size(YourArray,1)/60), 10*ones(1,size(YourArray,2)/10));
ans = 1×2
100 1
ans = 1×2
60 10
Walter Roberson
Walter Roberson on 13 Aug 2021
YourArray = randi(9, 6000, 10);
added_together = permute(sum(reshape(YourArray, 60, [], 10),2), [1 3 2]);
which is to say, do not break it into cell arrays if your plan is just to add them together.
If you need the call arrays for other reasons, then
added_together = sum(cat(3, subarrays{:}),3);

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!