how to split one dimensional array into 3 equal chunks?
이전 댓글 표시
Hi, I have the attached data array as an example, I need to split it into 3 equal chunks! Then I need to apply that for any other array with the same type but with different length.
댓글 수: 2
Adam Danz
2018년 9월 24일
There's one variable stored in your mat file so it would be a lot simpler to help you if you just describe that variable rather than require multiple people do download a mat file, load it in matlab, etc.
The variable Cb is a column vector of length 4897 which is not divisible by 3 so it is impossible to divide it into 3 chunks of equal length.
sana3 sal
2018년 9월 24일
채택된 답변
추가 답변 (1개)
This will take a column vector whose length is divisible by 3 and reshape it into a matrix with 3 columns of equal length. Each column of the new matrix will be one of your chunks.
Cb = (1:300)';
n = 3;
Cbmat = reshape(Cb, [], n);
Cbmat(:,1) is chunk 1, Cbmat(:,2) is chunk 2, etc.
This will break if Cb is not divisible by n.
카테고리
도움말 센터 및 File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!