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?
댓글 수: 0
답변 (1개)
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
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!