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?

Antworten (2)

KSSV
KSSV am 1 Aug. 2018

0 Stimmen

REad about datevec. With this you can get year, month, day, hour, minute and second information.
Stephen23
Stephen23 am 1 Aug. 2018
Bearbeitet: Stephen23 am 1 Aug. 2018

0 Stimmen

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 Kommentare

Luke Burl
Luke Burl am 1 Aug. 2018
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 am 1 Aug. 2018
Bearbeitet: Stephen23 am 1 Aug. 2018
"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 am 1 Aug. 2018
Much obliged, you are an officer and a gentleman... :)

Melden Sie sich an, um zu kommentieren.

Kategorien

Produkte

Version

R2016a

Tags

Gefragt:

am 1 Aug. 2018

Kommentiert:

am 1 Aug. 2018

Community Treasure Hunt

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

Start Hunting!

Translated by