Selecting Mondays from a Timetable or Table using the datetime object

Hi,
I would like to write a script that scrolls through my five minutes resolved timetable / table to select identifies all the days that are Mondays and then group them based on the datetime variable of the table/timetable.
I have tried several other ways to do it including the one below. Instead, if I specify the the day as 1, it returns all the first days of the periods (in this case months) and not specifically the Mondays.
Day1=HHB1(1==day(HHB1.VarName1),:); % HHB1 is the datetime object
%%
Any help?

 채택된 답변

Stephen23
Stephen23 2022년 3월 8일
편집: Stephen23 2022년 3월 8일
By default DAY returns the day of the month, so you need to specify its second argument like this:
d = day(t,'dayofweek')

댓글 수: 4

Thank you for the response @Stephen. However, the I still cannot subscript the dat set to get the day type I need. For instance, if I specify the following
Day1=HHB1(day(HHB1.VarName1,'dayofweek'),:);
The Day1 output is the same as the original dataset HHB1 with a single timestamp for all the entries. How would you recommend one moves from here
idx = day(HHB1.VarName1,'dayofweek')==7;
out = HHB1(idx,:);
Unfortunately MATLAB does not use the international standard of Monday==1: https://en.wikipedia.org/wiki/ISO_8601
Squeezing everything onto one line is not required and does not make the code more efficient. Clarity is better.
Thank you @Stephen. This returns the data I need.
@Lewis Waswa: Please remember to click the accept button if my answer helped you.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

제품

릴리스

R2021b

질문:

2022년 3월 8일

댓글:

2022년 3월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by