フィルターのクリア

How to merge two tables when the key variables are not common?

29 ビュー (過去 30 日間)
Iris Li
Iris Li 2018 年 5 月 11 日
コメント済み: Iris Li 2018 年 5 月 12 日
I have two tables A and B with key variables. Most variables are the same.
A = [X,Y,K;
100,200,1;
300,400,2;
500,600,3]
B = [P,Q,K;
1000,2000,1;
3000,4000,2;
5000,6000,3;
7000,8000,4]
how could I get
C = [X,Y,K,P,Q;
100,200,1,1000,2000;
300,400,2,3000,4000;
500,600,3,5000,6000;
Nah,Nah,4,7000,8000]

採用された回答

Guillaume
Guillaume 2018 年 5 月 11 日
編集済み: Guillaume 2018 年 5 月 11 日
This is called an outerjoin:
A = array2table([100 200 1; 300 400 2; 500 600 3], 'VariableNames', {'X', 'Y', 'K'});
B = array2table([1000 2000 1; 3000 4000 2; 5000 6000 3; 7000 8000 4], 'VariableNames', {'P', 'Q', 'K'});
C = outerjoin(A, B, 'MergeKeys', true)
Other types of joins are innerjoin and just plain join.
  4 件のコメント
Guillaume
Guillaume 2018 年 5 月 12 日
It's all documented in the link I provided, you can provide the keys with the Keys, LeftKeys, or RightKeys optional arguments.
Iris Li
Iris Li 2018 年 5 月 12 日
Thank you!!!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTables についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by