Assign user defined identifier from one table to another table

1 回表示 (過去 30 日間)
Yen Su
Yen Su 2021 年 1 月 28 日
編集済み: Siddharth Bhutiya 2021 年 1 月 29 日
Hi,
I have two excel file table; a.xlsx and b.xlsx. In a.xlsx file, identifier is assigned for different weight, height and width data column. The another excel file b.xlsx has also weight, height and width column with other data columns. I would like to assigned identifier of table a.xlsx in to table b.xlsx in new column. Any advice is appreciated.

採用された回答

Siddharth Bhutiya
Siddharth Bhutiya 2021 年 1 月 29 日
You can use outerjoin to do that. Your keys would be the three common variables and since you only want to add the extra identifier variable from a to b, you can specify MergeKeys to be true.
a = readtable('a.xlsx');
b = readtable('b.xlsx');
outerjoin(a,b,'Keys',{'height','weight','width'},'MergeKeys',true)
ans =
4×7 table
weight height width identifier serialNo age cost
______ ______ _____ __________ ________ ___ ____
502 101 52 1 1 34 4322
502 101 53 NaN 4 55 5533
515 101 53 3 3 43 2344
515 131 53 2 2 23 5433
  2 件のコメント
Yen Su
Yen Su 2021 年 1 月 29 日
This works. Is there a way to put serial no in first column, identifier in second column and after that other columns?
Siddharth Bhutiya
Siddharth Bhutiya 2021 年 1 月 29 日
編集済み: Siddharth Bhutiya 2021 年 1 月 29 日
You can use movevars for that
c = movevars(c,{'serialNo','identifier'},'Before',1)

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by