extract data from one day from a timetable
Show older comments
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));
Accepted Answer
More Answers (1)
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, :)
Categories
Find more on Matrices and Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!