How to append 2 tables with different columns

조회 수: 8 (최근 30일)
Shaochen Hu
Shaochen Hu 2022년 2월 14일
댓글: Shaochen Hu 2022년 2월 14일
I have 2 tables T1 and T2.
T1=3×2 table
Var1 Var2
____ ____
'A' 1
'B' 2
'C' 3
T2=3×2 table
Var1 Var3
____ ____
'D' 4
'E' 5
'F' 6
Is there a convenient way for me to get a combined table T3 like this?
T3=6×3 table
Var1 Var2 Var3
____ ____ ____
'A' 1 NaN
'B' 2 NaN
'C' 3 NaN
'D' NaN 4
'E' NaN 5
'F' NaN 6
Appriciated for your help!!!

채택된 답변

Matt J
Matt J 2022년 2월 14일
편집: Matt J 2022년 2월 14일
Use outerjoin().
T1=table(('ABC')',[1,2,3]');
T2=table(('DEF')',[1,2,3]'+3,'Var',{'Var1','Var3'});
outerjoin(T1,T2,'MergeKeys',1)
ans = 6×3 table
Var1 Var2 Var3 ____ ____ ____ A 1 NaN B 2 NaN C 3 NaN D NaN 4 E NaN 5 F NaN 6

추가 답변 (0개)

카테고리

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

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by