Extract partial data from datetime using logics/vectorization
Show older comments
Say I have some datetime data:
rowMin =
20×1 datetime array
02-Nov-2020 09:00:00
03-Nov-2020 09:10:00
04-Nov-2020 09:00:00
05-Nov-2020 09:14:59
06-Nov-2020 09:59:59
09-Nov-2020 09:05:00
10-Nov-2020 09:00:00
11-Nov-2020 09:35:00
12-Nov-2020 13:15:00
13-Nov-2020 09:00:00
16-Nov-2020 09:00:00
17-Nov-2020 15:00:00
18-Nov-2020 09:35:00
19-Nov-2020 10:15:00
20-Nov-2020 14:10:00
23-Nov-2020 16:35:00
24-Nov-2020 09:00:00
25-Nov-2020 11:15:00
26-Nov-2020 09:00:00
27-Nov-2020 10:20:00
where I wish to separate different weekdays (always Monday to Friday):
DayNumber=weekday(rowMin);
and then to extract hours and minutes for, respectively, Mondays, Tuesday, ..., Fridays, for subsequent analysis.
How to do this - preferably using logics and vectorization?
My first attempt:
MondayH=zeros(length(rowMin),1); % preallocation
MondayM=zeros(length(rowMin),1); % preallocation
for ii=1:length(rowMin)
if DayNumber(ii,1)==2 % Monday
[MondayH(ii,1),MondayM(ii,1),~]=hms(rowMin(ii,1));
end
end
Bonus info: I would like to utilize dur (duration) on the resulting array so that I afterwards can identify mean HH:mm of the individual days.
Accepted Answer
More Answers (0)
Categories
Find more on Dates and Time 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!