Combine two columns into one by first two rows A two rows B and so on
조회 수: 2 (최근 30일)
이전 댓글 표시
Hi, I want to combine two columns A and B (both 4x1) into one column C by using first the first two rows of A, then the first two rows of B, then the second two rows of A and so on.
A=[1,2,3,4]';
B=[-5,-6,-7,-8]';
I tried
N = size(A,1)+size(B,1) ;
C = zeros(N,1) ;
C(1:2:end) = A ;
C(2:2:end) = B ;
But not working.
Answer should be
C=[1;2;-5;-6;3;4;-7;-8]
댓글 수: 0
채택된 답변
Roger Stafford
2017년 12월 18일
C = reshape([reshape(A,2,[]);reshape(B,2,[])],[],1);
This depends on the lengths of the column vectors A and B being the same multiple of 2.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
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!