Get specific number of timetable rows after specific timedate

4 次查看(过去 30 天)
I've a timetable like the following one:
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
I also have a datetime object representing a date between the first and last value of my timetable:
checkDate =
datetime
03-Feb-2016 01:49:20
Now I want to retrieve two rows of my table. The row with the timestap that's just before my checkDate and the row just after it. In my case I need to retrieve these two rows:
% just before 03-Feb-2016 01:49:20
03-Feb-2016 01:49:18 1.0917
% just after 03-Feb-2016 01:49:20
03-Feb-2016 07:18:43 1.0919
I've seen that I can use timerange for it, but's not suited for my purposes. I need to set a start datetime and an end timedate for defining a timerange, and I don't know the distance between samples in my timetable, so I can miss values. I can have timetables where time intervals between consecutive rows span between one second and many years (they're result of some preprocessing).
Is there a way to obtain my result without using timerange or some linear search?

采纳的回答

Ameer Hamza
Ameer Hamza 2020-4-5
编辑:Ameer Hamza 2020-4-5
Try something like this
% example values
t = datetime('1/1/2020 00:00:00'):hours(8):datetime('31/1/2020 23:59:59');
val = rand(size(t));
t = timetable(t',val');
checkdate = datetime('1/15/2020 09:00:00');
idx = [find(t.Time < checkdate,1,'last') find(t.Time > checkdate,1,'first')];
values = t(idx,:);
  4 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Calendar 的更多信息

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by