Get specific number of timetable rows after specific timedate
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Daniele Lupo
el 5 de Abr. de 2020
Comentada: Ameer Hamza
el 5 de Abr. de 2020
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 comentarios
Respuesta aceptada
Ameer Hamza
el 5 de Abr. de 2020
Editada: Ameer Hamza
el 5 de Abr. de 2020
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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Calendar en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!