Clear Filters
Clear Filters

Synchronize / Outerjoin two timetables, without copying shared Variables.

5 views (last 30 days)
I have two timetables. They have some variable names in common, and some they don't.
They have no times in common.
Tt1 = (times1,'A','B','C');
Tt2 = (times2,'B','D');
T_join = [Tt1;Tt2]; %Doesn't work because some variables aren't the same
T_join = synchronize(Tt1,Tt2); % Gives me two 'B'-Colums ('B_1' and 'B_2')
I would like T_join to have the Variables ['A', 'B', 'C', 'D'] where 'B' is basically [B_1 ; B_2]
(Like outerjoin MergeKeys, I would like to merge colums, which outerjoin can't do with timetables).
Is there a function that can do this? Maye with a specific "Name,Value" combination?

Accepted Answer

Cris LaPierre
Cris LaPierre on 20 Jun 2024
outerjoin works with timetables. However, what you have shared here is not a timetable. Define your left and right keys to be times and the shared variable, then set the MergeKeys name-value pair to true to combine variables.
A = rand(10,1);
B = rand(10,1);
C = rand(10,1);
D = rand(10,1);
times1 = (datetime(2024,5,1):minutes(1):datetime(2024,5,1)+minutes(9))';
times2 = (datetime(2024,5,1):minutes(2):datetime(2024,5,1)+minutes(18))';
Tt1 = timetable(times1,A,B,C);
Tt2 = timetable(times2,B,D);
T_join = outerjoin(Tt1,Tt2,"LeftKeys",["times1","B"],"RightKeys", ["times2","B"],'MergeKeys',true)
T_join = 19x4 timetable
times1 A B C D ____________________ _______ _______ ________ ________ 01-May-2024 00:00:00 0.6419 0.27419 0.032145 0.67781 01-May-2024 00:01:00 0.83358 0.41592 0.20423 NaN 01-May-2024 00:02:00 0.02857 0.41196 0.71363 NaN 01-May-2024 00:02:00 NaN 0.41592 NaN 0.82575 01-May-2024 00:03:00 0.93037 0.35012 0.26219 NaN 01-May-2024 00:04:00 NaN 0.41196 NaN 0.22149 01-May-2024 00:04:00 0.84032 0.65943 0.55542 NaN 01-May-2024 00:05:00 0.48518 0.49822 0.15415 NaN 01-May-2024 00:06:00 0.14507 0.03919 0.7017 NaN 01-May-2024 00:06:00 NaN 0.35012 NaN 0.61163 01-May-2024 00:07:00 0.99798 0.66835 0.83783 NaN 01-May-2024 00:08:00 0.94594 0.60982 0.67436 NaN 01-May-2024 00:08:00 NaN 0.65943 NaN 0.065609 01-May-2024 00:09:00 0.41493 0.19695 0.52029 NaN 01-May-2024 00:10:00 NaN 0.49822 NaN 0.32259 01-May-2024 00:12:00 NaN 0.03919 NaN 0.056516

More Answers (0)

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!