How to arrange alternate cells of a column into two columns?
조회 수: 1 (최근 30일)
이전 댓글 표시
Let's say the column matrix is:
A =
2
6
7
3
8
3
2
9
7
5
4
1
And I need to obtain final result as
A =
2 6
7 3
8 3
2 9
7 5
4 1
Can I know the way to split in this way?
댓글 수: 0
채택된 답변
Florian Bidaud
2023년 8월 16일
편집: Florian Bidaud
2023년 8월 16일
A = [2 6 7 3 8 3 2 9 7 5 4 1]'
B = [A(1:2:end) A(2:2:end)]
댓글 수: 3
Dyuman Joshi
2023년 8월 16일
That depends on the size you want to arrange -
%For a 2D array, define atleast one dimension
ncol = 2;
A = [2 6 7 3 8 3 2 9 7 5 4];
%Convert to column vector
A = A(:);
%Add required zeros
A = [A;zeros(1,rem(numel(A),ncol))];
B = reshape(A,ncol,[])'
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!