How to extract elements from datetime variable

I have a datetime variable of 1048576x1 elements, I can convert the format to various options, including showing the days of the week (which is what I am interested in). However, I need to find certain elements in the variable corresponding to a specific day. How can this be done?

回答 (2 件)

KSSV
KSSV 2018 年 8 月 1 日

0 投票

REad about datevec. With this you can get year, month, day, hour, minute and second information.
Stephen23
Stephen23 2018 年 8 月 1 日
編集済み: Stephen23 2018 年 8 月 1 日

0 投票

To get the weekday from a datetime variable use weekday. Unfortunately this returns the weekday with Sunday=1 (and thus does not match ISO 8601 or most of the world), but a simple mod call could fix that.
Or take mod of a serial date number to get the day of the week:
1+mod(datenumber-3,7)

3 件のコメント

Luke Burl
Luke Burl 2018 年 8 月 1 日
but how do I search for a specific day? My data is sampled every minute and I have a couple of years' worth of data, so I have 1440 elements for each day and ~900 days' data. I need to identify, e.g. all Tuesdays within the data set? The complexity is that I can't use the number of elements as I have some missing data so odd number of elements with respect to each day.
Stephen23
Stephen23 2018 年 8 月 1 日
編集済み: Stephen23 2018 年 8 月 1 日
"but how do I search for a specific day?"
If you want to check if a particular day exists in your datetime array or weekday then just use a logical comparison, or ismember:
weekday(yourarray)==3
Luke Burl
Luke Burl 2018 年 8 月 1 日
Much obliged, you are an officer and a gentleman... :)

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeDates and Time についてさらに検索

製品

リリース

R2016a

タグ

質問済み:

2018 年 8 月 1 日

コメント済み:

2018 年 8 月 1 日

Community Treasure Hunt

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

Start Hunting!

Translated by