Group all the columns every N rows
조회 수: 5 (최근 30일)
이전 댓글 표시
Hi everyone,
i have an array like this:
A
0.5 0.4 0.5
0.9 0.3 0.5
0.5 0.5 0.1
0.5 0.4 0.2
0.9 0.8 0.2
0.3 0.5 0.2
and i want to create a cell arrays like these (group all the columns every N rows, with N=2):
{A1}
0.5 0.4 0.5
0.9 0.3 0.5
{A2}
0.5 0.5 0.1
0.5 0.4 0.2
{A3}
0.9 0.8 0.2
0.3 0.5 0.2
How can i do it?
Thank you very much!
댓글 수: 0
채택된 답변
madhan ravi
2019년 1월 24일
편집: madhan ravi
2019년 1월 24일
Your way:
N=2;
A=mat2cell(a,repelem(N,size(a,1)/N));
celldisp(A)
댓글 수: 0
추가 답변 (1개)
madhan ravi
2019년 1월 24일
편집: madhan ravi
2019년 1월 24일
One way:
N=2;
[~,c]=size(A);
U=reshape(A',c,N,[]);
R=permute(U,[2 1 3])
댓글 수: 4
madhan ravi
2019년 1월 29일
I see you have asked another question regarding this issue but here is one solution:
N=4;
[m,c]=size(A);
U=reshape(A',m,[],N);
R=permute(U,[1 3 2]);
BB=reshape(R,N,[],1)'
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!