Clear Filters
Clear Filters

Single average value for same range of time each day throughout the year

1 view (last 30 days)
Hello,
I am currently looking for a way to average my dataset for a period of 4 minutes each day. For my current analysis, I am only interested in the specific value at 5pm (17:00:00). Sometimes though, this data point is missing, so I had thought to take an average from 16:58 to 17:02. I had attempted to work through this, using my test Time_Vector (attached) as a reference. My current code unfortunately also returns 16:00:00 - 16:01:59 as well as 17:58:00 - 17:59:59, so at this time I am unable to accurately average my dataset. I would then use the index created to split up my Time_Vector against my y-data to find a specific value each day.
(i.e. Test_Y = Test_Y(mt_id) or Test_Y = Test_Y(Times_to_Keep_id))
H = hour(Time_Vector);
hr_id = H >= 16 & H <= 17;
Time_Vector2 = Time_Vector(hr_id);
mt_id = minute(Time_Vector2) > 58 | minute(Time_Vector2) < 02;
Time_Vector3 = Time_Vector2(mt_id);
% Times_to_Keep_id = hr_id & mt_id;
Thank you for your help.

Accepted Answer

Cris LaPierre
Cris LaPierre on 8 Jan 2021
Edited: Cris LaPierre on 8 Jan 2021
You need to combine your conditions for hours and minutes. Consider using the timeofday function instead.
load Time_Vector
Tind = timeofday(Time_Vector) >= duration(16,58,0) & timeofday(Time_Vector) <= duration(17,02,0);
Time_Vector(Tind,1)
ans = 24×1 datetime array
19-Jul-2017 16:58:03 19-Jul-2017 16:58:18 19-Jul-2017 16:58:33 19-Jul-2017 16:58:48 19-Jul-2017 16:59:03 19-Jul-2017 16:59:18 19-Jul-2017 16:59:33 19-Jul-2017 16:59:48 19-Jul-2017 17:00:03 19-Jul-2017 17:00:18 19-Jul-2017 17:00:33 19-Jul-2017 17:00:48 19-Jul-2017 17:01:03 19-Jul-2017 17:01:18 19-Jul-2017 17:01:33 19-Jul-2017 17:01:48 20-Jul-2017 16:58:03 20-Jul-2017 16:58:18 20-Jul-2017 16:58:33 20-Jul-2017 16:58:48 20-Jul-2017 16:59:03 20-Jul-2017 16:59:18 20-Jul-2017 16:59:33 20-Jul-2017 16:59:48

More Answers (0)

Categories

Find more on Loops and Conditional Statements 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!