필터 지우기
필터 지우기

Ask for creating new matrix from Odd-Indexed and Even-Indexed Elements

조회 수: 3 (최근 30일)
Hi,
I have two existing matrix with element of 371x2 and I would like to create the new one with 743x2 by putting the odd row with first matrix and even row with the second matrix following sample below;
Matrix A
1 2
5 6
9 10
. .
. .
Matrix B
3 4
7 8
11 12
. .
. .
New matrix C
1 2
3 4
5 6
7 8
9 10
11 12
. .
. .
I try the code following below but it didn't work. Could you please correct my code.
C = zeros(743,2);
[C(1:2:end,:),C(2:2:end,:)] = (A,B);
Thanks

채택된 답변

David Goodmanson
David Goodmanson 2017년 12월 3일
편집: David Goodmanson 2017년 12월 3일
Hi Phat,
you're close
C = zeros(742,2);
C(1:2:end,:) = A;
C(2:2:end,:) = B;
  댓글 수: 2
Phat Pumchawsaun
Phat Pumchawsaun 2017년 12월 3일
편집: Phat Pumchawsaun 2017년 12월 3일
Hi David,
Many thanks to this. Once again, if I would like to add one more column with an array of 371x1 to be in the 3rd coloumn of matrix C. How can I code it?
Thanks
David Goodmanson
David Goodmanson 2017년 12월 3일
right now C is 742x2 and your new matrix D is 371x1. You can't make a third column of C with it because it doesn't have enough rows. Would you put zeros for the rest of the rows?

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by