필터 지우기
필터 지우기

combination of two matrices

조회 수: 1 (최근 30일)
Najiya Omar
Najiya Omar 2016년 12월 12일
댓글: James Tursa 2016년 12월 13일
I have two matrices (160,12) in size. I want to put them in one matrix (320,12)by making the first 40 rows in matrix 1 following by the first 40 rwos in matrix 2, creating the first 80 rows of the new matrix. the second 40 rows in matrix 1 following by the second 40 rwos in matrix 2, creating the second 80 rows and so on.
Thank you in advance!!!

채택된 답변

James Tursa
James Tursa 2016년 12월 13일
A = 160 x 12 matrix
B = 160 x 12 matrix
Ar = reshape(A',40*12,[]);
Br = reshape(B',40*12,[]);
result = reshape([Ar;Br],12,[])';
  댓글 수: 1
Najiya Omar
Najiya Omar 2016년 12월 13일
Amazing!! thank you James so so much

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

추가 답변 (1개)

John BG
John BG 2016년 12월 13일
There is not need to reshape
[szA1 szA2]=size(A);[szB1 szB2]=size(B);
[A(:,[1:floor(szA2/2)]) B(:,[1:floor(szA2/2)]) A(:,[floor(szA2/2)+1:end]) B(:,[floor(szA2/2)+1:end])]
  댓글 수: 3
John BG
John BG 2016년 12월 13일
reshaping implies pulling all elements one by one, putting them in a long string, and then putting them back in the desired matrix shape.
Instead, by directly addressing a partial range of the original matrix oneu saves time that may be noticeable if the matrix is big.
Regards
John BG
James Tursa
James Tursa 2016년 12월 13일
Reshaping a full matrix produces a shared data copy, not a deep data copy. So no elements get moved in memory at all.

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

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by