Outerjoining timetables giving unwanted NaN/NaT values

2 次查看(过去 30 天)
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 中查找有关 Dates and Time 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by