using datetime() in retrieving data
조회 수: 1(최근 30일)
Assuming I am using datetime() to refer to the date and time that some data has accured in.
I am using 'date' in further comparison to retrive some data, now is there any syntax I may use in this that would allow me for example to retrive the data happened in a certain day for all the years, (ex: the data happened in 1st october from all the years we have) or for a certain hour from all days in months in years?
Siddharth Bhutiya 2021년 9월 30일
Once you have created a datetime array, you could use functions like month, day, year, etc to get the corresponding field values from the datetime. Then as KSSV suggested above, you could use those to index and filter your datetimes.
4×1 datetime array
>> d(month(d) == 10 & day(d) == 1) % Get 1st October for all years
2×1 datetime array
If you want to filter your datetimes for values between two points in time then you could also use something like isbetween: https://www.mathworks.com/help/matlab/ref/datetime.isbetween.html
KSSV 2021년 9월 30일
Read about datevec. This will split your date into year, month, day, hour, minute and secobd. From here you can use logial indexing and get the indices.
idx = month == 10 & day == 1 ;