Outerjoining timetables giving unwanted NaN/NaT values

5 views (last 30 days)
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 Comment
millercommamatt
millercommamatt on 6 Oct 2021
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.

Sign in to comment.

Answers (0)

Categories

Find more on Shifting and Sorting Matrices in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!