how to merge two matrices via one common column
이전 댓글 표시
Hi there. My question is that I have two matrices, say, A and B, A have two columns, 1 and 2, B has two columns, 3 and 4. Columns 2 and 3 are actually same numbers, BUT with difference order. How can I merge them together? For example, column 2 of matrix A is [a b c d e f]' and column 3 of matrix B is [d c b a e f]'. All the letters are unique ones. Is there an easy way to merge A and B?
댓글 수: 1
채택된 답변
추가 답변 (1개)
Anew=sortrows(A,2);
Bnew=sortrows(B,1);
merged=[Anew,Bnew(:,2)];
카테고리
도움말 센터 및 File Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!