How do I join two tables based on time to the second. attempts are yielding multiple rows

조회 수: 4 (최근 30일)
I have two tables with one second data. Both tables have many 'blocks' of rows, and gaps in time between those blocks. My desired result is to NOT include rows for those gaps. Hence, I do not believe using synchronize (e.g. synchronize(T1, T2,'secondly','next') would work (resulted in a large expansion of the table to include filled-in data in those gaps).
Both T1 and T2 are tables (one was changed to table from timetable).
Time variable in both tables are class 'datetime'. I used the below to remove any data smaller than seconds (I think).
T1.Time = datetime(year(T1.Time),month(T1.Time),day(T1.Time),hour(T1.Time),minute(T1.Time),second(T1.Time));
The Time variable of both tables have different and overlapping ranges. My goal is to pull the data from T2 that corresponds to the Time in T1.
note: both tables have another key variable (e.g. key2) , which is not shown and not used in my attempt below. I might join the two tables from files that are already filtered for a specific key2 value, instead joining one large file that includes all groups defined by key2.
I tried
combined = outerjoin(T1,T2, 'Keys',{'Time'});
(I copied a portion of my matlab results into excel to create these graphics)
Any idea why the incorrect result?

답변 (1개)

Walter Roberson
Walter Roberson 2022년 12월 2일
이동: Walter Roberson 2022년 12월 5일
Instead of using that particular code I suggest that you use dateshift(T1.Time, 'start', 'second')
  댓글 수: 1
Ted HARDWICKE
Ted HARDWICKE 2022년 12월 5일
이동: Walter Roberson 2022년 12월 5일
dateshift() worked. I used between() and there was still a 1e-6 duration between the two dates. dateshift() got rid of that, and it now lines up.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Data Type Identification에 대해 자세히 알아보기

태그

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by