Modified version of VLOOKUP for Matlab

1 回表示 (過去 30 日間)
Jules
Jules 2016 年 3 月 28 日
編集済み: Jules 2016 年 3 月 28 日
So I have a table(A) containing:
  1. companies IDs (ID)
  2. An announcement date (AD) for each ID(an ID can have multiple dates)
  3. Price (PC).
The table is 15000 x 3
I have a second table(B) containing:
  1. companies IDs (ID)
  2. announcement dates(AD) for each ID(an ID can have multiple dates)
  3. and a couple of other variables irrelevant to this situation.
The table is 14990 x 3.
I am looking to add on Table(B), the prices of table(A) of each company ID and Announcement Date that match the ID and AD of table B.
Please look at attachment for example.
I would like a code to add to table B, a Price of 300 for the second row (ID=02).
Thank you for your help!

採用された回答

Teja Muppirala
Teja Muppirala 2016 年 3 月 28 日
You can do this using OUTERJOIN .
A = table;
A.ID = [1;1;2];
A.AD = datetime({'2016/01/01'; '2015/02/02'; '2010/3/3'});
A.PC = [100;200;300];
B = table;
B.ID = [1;2];
B.AD = datetime({'2012/01/01'; '2010/3/3'});
B.Irrelevant = {'aaa'; 'bb'};
B_Price = outerjoin(A,B,'type','right','MergeKeys',true)
This gives you
B_Price =
ID AD PC Irrelevant
__ __________ ___ __________
1 2012/01/01 NaN 'aaa'
2 2010/03/03 300 'bb'
  1 件のコメント
Jules
Jules 2016 年 3 月 28 日
編集済み: Jules 2016 年 3 月 28 日
This worked brilliantly! I had to slightly modify my code as i have 700 "irrelevant" variables Thank you!

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

その他の回答 (0 件)

カテゴリ

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

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by