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?
0 个评论
采纳的回答
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,:);
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Calendar 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!