extract data from one day from a timetable
27 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Fabio
el 5 de Jul. de 2022
Comentada: Star Strider
el 8 de Jul. de 2022
Hello everybody
I've a timetable with multiple variabiles and the time column containg both day and hour information. If I choose a day I would like to be able to extract from timetable all data collected during that day (that are many).
Now if I try to do that I only manage to extract the first value for that day, but remaing ones (after midnight) are not collected.
t0 = datetime(2006,01,01);
TT2.LivelloIdrometricoCorr(TT2.InizioValiditUTC(t0));
0 comentarios
Respuesta aceptada
Star Strider
el 5 de Jul. de 2022
Try something like this —
LD = load('ask_matlab.mat');
TT1 = LD.ans;
RT = TT1.Properties.RowTimes;
VN = TT1.Properties.VariableNames;
DayMthLv = day(RT) == 1 & month(RT) == 1; % Logical Vector
Mon1Day1 = TT1(DayMthLv,:) % Data For January 1, 2006
Running that code offline (since .mat files are not yet supported here) produces the appropriate result, a (48x2) timetable of the selected dates.
.
2 comentarios
Más respuestas (1)
Steven Lord
el 5 de Jul. de 2022
Use a timerange. First generate some sample data with datetime values representing random hours in July 2022.
rng default % for reproducibility
dt = datetime(2022, 7, randi(31, 10, 1), randi([0 23], 10, 1), 0, 0);
x = (1:10).';
tt = timetable(dt, x)
Let's retrieve all the rows of tt from July 4th. We make a timerange that starts at midnight on the 4th and ends just before midnight on the 5th.
fourth = datetime(2022, 7, 4);
tr = timerange(fourth, fourth+days(1))
Finally use tr to index into tt.
dataFromFourth = tt(tr, :)
0 comentarios
Ver también
Categorías
Más información sobre Dates and Time 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!