Join tables based on month values

2 visualizaciones (últimos 30 días)
shi hao lee
shi hao lee el 30 de Mzo. de 2021
Respondida: Prahlad Gowtham Katte el 14 de Feb. de 2022
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?

Respuestas (1)

Prahlad Gowtham Katte
Prahlad Gowtham Katte el 14 de Feb. de 2022
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

Categorías

Más información sobre Logical en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by