could anyone help me how to pair the numbers in the desired manner as shown below
조회 수: 1 (최근 30일)
이전 댓글 표시
A=1:16
R = reshape(A,4,[])
After executing the above command results in
R =
1 5 9 13
2 6 10 14
3 7 11 15
4 8 12 16
Now I want to group the numbers in the desired manner
1 2 3 4 5 6 7 8
12 11 10 9 16 15 14 13
Could anyone please help me on this.
댓글 수: 0
채택된 답변
Dyuman Joshi
2021년 11월 2일
This looks a quite a unique manner. Anyways, try this
A=1:16;
R = reshape(A,4,[]);
[R(:,1)' R(:,2)'; flip(R(:,3))' flip(R(:,4))']
댓글 수: 3
Dyuman Joshi
2021년 11월 3일
편집: Dyuman Joshi
2021년 11월 3일
I am not sure what you mean by combining all into a single code, so here's my approach -
for i=[3 4 6 9 12]
z=1:4*i;
y=reshape(z,[],4);
R=[y(:,1)' y(:,2)'; flip(y(:,3))' flip(y(:,4))']
end
Here R will be modified in each iteration. You can modify the code according to however you want to proceed.
추가 답변 (1개)
Yongjian Feng
2021년 11월 2일
reshape(A, 8, 2)'
댓글 수: 2
Yongjian Feng
2021년 11월 2일
Whoops. Didn't pay attention to the order of the second row.
Then we need to use flip most likely.
A=1:16
R = reshape(A,4,[]);
R(:, 3) = flip(R(:, 3));
R(:, 4) = flip(R(:, 4));
ret = reshape(R, 8, 2)'
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!