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 Center および File ExchangeShifting 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