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

问题描述 投票:0回答:1

我在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。这是过去和将来与intersectionPoints相关的checkDatecheckDate的两个最近点。我可以遍历所有时间戳值并手动检查它们,但是效率不高(我的时间表很大)。我也可以对这些元素执行手动二进制搜索,但是我想知道是否存在内置的或更简单的方法来搜索这两个值。

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

matlab search timetable
1个回答
0
投票
关于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,:)

© www.soinside.com 2019 - 2024. All rights reserved.