Synchronize / Outerjoin two timetables, without copying shared Variables.
4 views (last 30 days)
Show older comments
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?
0 Comments
Accepted Answer
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)
0 Comments
More Answers (0)
See Also
Categories
Find more on Timetables in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!