joining non uniform and uniform tables with a datetime

Hi - have two set of data. One is per second uniform data for 4 months and another is non-uniform datetime data. I would like to insert the non-uniform data into the uniform set wherever the datetimes match up. I tried join and got the error "The key variable for B must contain all values in the key variable for A." but because the second data is non-uniform but still sequential it only has datetimes for when the variable is on or off, somewhat random. innerjoin returns an empty table and then outer join dosen't seem to be picking up the datetimes correctly. The per second data comes from multiple text files whilst the none uniform data are csv files. Perhaps there is an easier way of joining the data?? Thanks in advance

Answers (2)

Do you want the data in the resulting table (actually, I assume you mean timetable) to all be in the same variable or in different variables? In the former case, and if the two timetable arrays have the same variables, concatenate them and sortrows.
% Create the two timetable arrays with different times but the same variable name
TimeDuration = [hours(3) hours(2) hours(1) hours(5) hours(6)]';
TT1 = timetable(TimeDuration,[98;97.5;97.9;98.1;101]);
TimeDuration = [hours(4) hours(1.5) hours(0.5) hours(3.125) hours(5.1)].';
TT2 = timetable(TimeDuration,[120;111;119;117;118]);
% Concatenate
TT = [TT1; TT2]
% Sort by the times
B = sortrows(TT,'TimeDuration')
If you want the data to be in different variables in the combined timetable you can synchronize them.
C = synchronize(TT1, TT2, 'union')
It's not clear what you mean by, "insert the non-uniform data into the uniform set". Yopu might mean what Steve thinks you mean. But to me it sounds like you want a left outer join. Not sure why that's not working for you, you should make sure your times are what you think they are.

Asked:

on 25 Oct 2017

Answered:

on 16 Nov 2017

Community Treasure Hunt

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

Start Hunting!