Join tables based on month values

1 次查看(过去 30 天)
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
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 CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by