extract data from one day from a timetable

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));

 采纳的回答

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 个评论

Thank you,
I've actually tried to use your code adding:
DayMthLv = day(RT) == giorno & month(RT) == mese & year(RT) == anno; % Logical Vector
and performing an implementation with 3 for cycles, in order to execute this operation for each day from my time series.
I'm gonna make an attempt to verify if it works,
thank you for help and support.
Have a nice week end
As always, my pleasure!
You, too!
.

请先登录,再进行评论。

更多回答(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)
tt = 10×1 timetable
dt x ____________________ __ 26-Jul-2022 03:00:00 1 29-Jul-2022 23:00:00 2 04-Jul-2022 22:00:00 3 29-Jul-2022 11:00:00 4 20-Jul-2022 19:00:00 5 04-Jul-2022 03:00:00 6 09-Jul-2022 10:00:00 7 17-Jul-2022 21:00:00 8 30-Jul-2022 19:00:00 9 30-Jul-2022 23:00:00 10
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))
tr =
timetable timerange subscript: Select timetable rows with times in the half-open interval: [04-Jul-2022 00:00:00, 05-Jul-2022 00:00:00) See Select Timetable Data by Row Time and Variable Type.
Finally use tr to index into tt.
dataFromFourth = tt(tr, :)
dataFromFourth = 2×1 timetable
dt x ____________________ _ 04-Jul-2022 22:00:00 3 04-Jul-2022 03:00:00 6

类别

帮助中心File Exchange 中查找有关 Timetables 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by