how to extract n rows in a matrix column iteratively?
이전 댓글 표시
i have a matrix A(15,1) looking like this
0.4218
0.9157
0.7922
0.9595
0.6557
0.0357
0.8491
0.9340
0.6787
0.7577
0.7431
0.3922
0.6555
0.1712
0.7060
I want to extract always 3 rows iteratively and put it in a cell,
In the first cell i want to have
0.4218
0.9157
0.7922
in the second cell i want to have
0.9595
0.6557
0.0357
and so on..., i would then end up with 5 cells as this {1,5}(3,1)
is there an easy way to do it without writing several for loops?
Thanks already in advance!
채택된 답변
추가 답변 (1개)
Andrei Bobrov
2020년 3월 3일
편집: Andrei Bobrov
2020년 3월 3일
out = num2cell(reshape(A,3,[]),1);
or
out = accumarray(ceil((1:numel(A))'/3),A,[],@(x){x});
카테고리
도움말 센터 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!