필터 지우기
필터 지우기

Split Matrix into multiple Submatrices

조회 수: 14 (최근 30일)
Avik Mahata
Avik Mahata 2021년 8월 12일
댓글: Walter Roberson 2021년 8월 13일
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?

채택된 답변

Walter Roberson
Walter Roberson 2021년 8월 12일
YourArray = randi(9, 6000, 10);
subarrays = mat2cell(YourArray, 60*ones(1,size(YourArray,1)/60), 10*ones(1,size(YourArray,2)/10));
size(subarrays)
ans = 1×2
100 1
size(subarrays{1,1})
ans = 1×2
60 10
  댓글 수: 2
Avik Mahata
Avik Mahata 2021년 8월 13일
Thanks. It worked. Thanks for taking time to reply. Its extemely helpful for my reserach.
I need another help about the cell operation. How can I add those 60 rows with each other in the cell. I meant to say, Row 1 (first cell) + Row 1 (second cell)+...., and repeat it for all 60 rows and get a final 60x10 matrix.
Walter Roberson
Walter Roberson 2021년 8월 13일
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);

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by