Outerjoining timetables giving unwanted NaN/NaT values

6 visualizzazioni (ultimi 30 giorni)
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 Commento
millercommamatt
millercommamatt il 6 Ott 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.

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Shifting and Sorting Matrices in Help Center e File Exchange

Prodotti


Release

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by