检索特定时间数据旁边的 matlab 时间表点

Retrieve matlab timetable points next to specific timedata

我在 Matlab 中有以下 timetable

intersectionPoints =

  10×1 timetable

         Timestamp          Value 
    ____________________    ______

    01-Feb-2016 00:00:00    1.0848
    01-Feb-2016 01:00:00    1.0847
    01-Feb-2016 04:00:00    1.0848
    02-Feb-2016 14:07:44    1.0914
    02-Feb-2016 17:21:36    1.0916
    03-Feb-2016 01:49:18    1.0917
    03-Feb-2016 07:18:43    1.0919
    04-Feb-2016 00:53:20    1.1088
    04-Feb-2016 04:18:16    1.1097
    04-Feb-2016 21:38:10    1.1199

我还有以下 timedate:

checkDate = datetime("03-Feb-2016 01:49:20")

checkDate = 

  datetime

   03-Feb-2016 01:49:20

我想从 intersectionPoints 时间表中检索特定时间戳的前一行和下一行的行。在我的具体情况下,我需要检索两点:

res =

  2×1 timetable

         Timestamp          Value 
    ____________________    ______

    03-Feb-2016 01:49:18    1.0917
    03-Feb-2016 07:18:43    1.0919

res 是具有两个元素的 timetable。这是intersectionPointscheckDate最近的两个点,过去和将来与checkDate有关。我可以遍历所有时间戳值并手动检查它们,但效率不高(我的时间表很大)。我也可以对这些元素执行手动二进制搜索,但我想知道是否有内置或更简单的方法来搜索这两个值。

如何找到定义值旁边的 timetable 个值?

MATLAB 最酷的地方在于它是为工程师创建的,并且应该像非信息学人员所期望的那样工作。所以简单地 find 第一个 (find(...,1)) 元素比你的 checkDate:

>
time = [datetime('yesterday')
        datetime('today')
        datetime('tomorrow')];
checkDate = datetime('now');
Tbl = timetable(time,(1:length(time)).');

idx = find(Tbl.time > checkDate ,1);

res = Tbl(idx-1:idx,:)