split a n*m-by-1 vector into n m-by-1 vectors
이전 댓글 표시
I would like to split a m*n-by-1 vector into smaller ones, e.g. m-by-1. I have tried to think of an efficient way but i have not.
Any ideas?
Thank you.
채택된 답변
추가 답변 (2개)
Benjamin Avants
2014년 3월 14일
I think the easiest method uses num2cell:
myArray = ones(3,4,1);
myCell = num2cell(myArray,1)
ans =
[3x1 double] [3x1 double] [3x1 double] [3x1 double]
You then have a 4 element cell array of 3x1 numerical arrays. Not sure if that's what you're looking for, but perhaps its a step in the right direction. The second parameter of num2cell determines which dimension is split into cells. Making that argument a 2 would yield a 3 element cell array of 4x1 numerical arrays.
Joseph Cheng
2014년 3월 14일
0 개 추천
How about putting it into the 3rd dimension? A=reshape(A,2,1,4) then you can reference A(:,:,1) to A(:,:,4) will be the smaller ones?
카테고리
도움말 센터 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!