Join tables based on month values

1 回表示 (過去 30 日間)
shi hao lee
shi hao lee 2021 年 3 月 30 日
回答済み: Prahlad Gowtham Katte 2022 年 2 月 14 日
I want to join the tables by month to give 3 rows, one for each month.
The first row should be Jun-2018, Jun-2018. Second should be Jul-2018, Jul-2018. Last row should be Aug-2018, Aug 2018.
However, the original data is 1st June and 2nd June and it is causing the join to give me 6 rows.
a = table(datetime({'01-Jun-2018'; '01-Jul-2018'; '01-Aug-2018'}))
b = table(datetime({'02-Jun-2018'; '02-Jul-2018'; '02-Aug-2018'}))
a2 = table(datetime(a.Var1,"Format","MMM-uuuu"))
b2 = table(datetime(b.Var1,"Format","MMM-uuuu"))
outerjoin(a2,b2,'Keys','Var1')
Any solutions?

回答 (1 件)

Prahlad Gowtham Katte
Prahlad Gowtham Katte 2022 年 2 月 14 日
Hello,
As per my understanding of the query, you are trying to join two tables with similar month values using outer join. Your intended result can be achieved if you set MergeKeys to true in outer join function. If you replace the line which calls outer join function with the following it would resolve the problem.
outerjoin(a2,b2,"Keys","Var1","MergeKeys",true);
For more detailed explanation about the outer join function following link can be useful.
Hope it resolves your problem

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by