Outerjoining timetables giving unwanted NaN/NaT values

조회 수: 5 (최근 30일)
millercommamatt
millercommamatt 2021년 10월 6일
댓글: millercommamatt 2021년 10월 6일
I'm trying to outerjoin two timetables using a common non-time key.
Here's an example:
>> Tleft = timetable(seconds([1;2;4;6]),[1 2 3 11]');
>> Tright = timetable(seconds([2;4;6;7]),[1 3 6 7]');
>> T1 = outerjoin(Tleft,Tright,'Keys',{'Var1','Var1'})
T1 =
6×2 timetable
Time Var1_Tleft Var1_Tright
_______ __________ ___________
1 sec 1 1
2 sec 2 NaN
4 sec 3 3
NaN sec NaN 6
NaN sec NaN 7
6 sec 11 NaN
>>
I'd like to bring in the time from the right table instead of having a NaN/NaT. How do I do that?
  댓글 수: 1
millercommamatt
millercommamatt 2021년 10월 6일
As is typical, I found a solution to my own question.
This syntax will allow you to bring over the missing times from the right table.
Tleft = timetable(seconds([1;2;4;6]),[1 2 3 11]');
Tright = timetable(seconds([2;4;6;7]),[1 3 6 7]');
[T1,~,iright] = outerjoin(Tleft,Tright,'Keys',{'Var1','Var1'});
T1.Time(isnan(T1.Time))=Tright.Time(iright(isnan(T1.Time)))
T1 =
6×2 timetable
Time Var1_Tleft Var1_Tright
_____ __________ ___________
1 sec 1 1
2 sec 2 NaN
4 sec 3 3
6 sec NaN 6
7 sec NaN 7
6 sec 11 NaN
I hope this help someone else.
Outerjoin need a MergeTime function similar to how it has MergeKeys.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by