Split a larger matrix into smaller matrices

조회 수: 1 (최근 30일)
Kash022
Kash022 2016년 3월 17일
댓글: Star Strider 2016년 3월 17일
Hello All,
I have a [256 x 5 x 2000] matrix. I want to split this matrix into 5 [256 x 1 x 2000] matrices. Tried using mat2cell but it returns an error stating number of dimensions must match.
Could anyone please help me with this?
Thanks, \Kashif

채택된 답변

Star Strider
Star Strider 2016년 3월 17일
The dimensions have to add to the same values in each dimension with mat2cell.
This works:
M = randi(9, 256, 5, 2000); % Create Matrix
C = mat2cell(M, 256, ones(1,5), 2000); % Split To Cells
  댓글 수: 6
Kash022
Kash022 2016년 3월 17일
@Star Strider: Yeps this works...even if I do plot(squeeze(C{1}(1,1,:))); Thanks!
Star Strider
Star Strider 2016년 3월 17일
My pleasure!

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

추가 답변 (1개)

Andrei Bobrov
Andrei Bobrov 2016년 3월 17일
C = num2cell(M,[1 3]);
  댓글 수: 5
Stephen23
Stephen23 2016년 3월 17일
편집: Stephen23 2016년 3월 17일
@ksnf3000: why are you using both num2cell and mat2cell? None of the answers do this. mat2cell splits up your array into pieces and returns a cell array... why do you want to split this up as well? You only need one of them.
Kash022
Kash022 2016년 3월 17일
@Stephen Cobeldick: Yes , your right...can use any one. Thanks once again!

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

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by