필터 지우기
필터 지우기

Clubbing of two matrices rows altenately

조회 수: 1 (최근 30일)
Danish Nasir
Danish Nasir 2021년 6월 27일
댓글: Danish Nasir 2021년 6월 27일
i have two matrices A & B. The no. of rows in A are 4 and elements 5. The no. of rows in B are 3 and elements 5.
I want to create matrix C such that its first row is first row of A. Then C second row should be 1st row of B.
E.g A= [ 1 3 4 5 7 ;4 5 6 6 7;5 3 2 1 2; 2 2 2 3 4 ]
B=[1 1 1 2 3 ;1 2 4 6 7 ;3 5 6 7 8 ]
Then C should be C=[1 3 4 5 7 ;1 1 1 2 3;4 5 6 6 7;1 2 4 6 7 ;5 3 2 1 2 ;3 5 6 7 8 ;2 2 2 3 4]
It is requested to provide me the code so that i can generate matrix C as mentioned above (i.e. alternate rows of A & B)

채택된 답변

DGM
DGM 2021년 6월 27일
편집: DGM 2021년 6월 27일
Try something like:
A = [1 3 4 5 7; 4 5 6 6 7; 5 3 2 1 2; 2 2 2 3 4];
B = [1 1 1 2 3 ; 1 2 4 6 7; 3 5 6 7 8];
C = zeros(size(A,1)+size(B,1),size(A,2));
C(1:2:end,:) = A;
C(2:2:end,:) = B;
C = 7×5
1 3 4 5 7 1 1 1 2 3 4 5 6 6 7 1 2 4 6 7 5 3 2 1 2 3 5 6 7 8 2 2 2 3 4
  댓글 수: 1
Danish Nasir
Danish Nasir 2021년 6월 27일
Thanx for the prompt solution
Regards
Danish

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by