Novice_Developer
Novice_Developer

Reputation: 1492

Find indices for a specific time

Lets suppose I have a datetime vector

>> t = datetime('now','Format','d-MMM-y HH:mm:ss');
>> t2 = datetime('now','Format','d-MMM-y HH:mm:ss') +5;
>> DV = t:1/288:t2;

now I want to ind all the indices which have time between 5:00 and 6:00 is there any elegant way to do it without using a for loop

Upvotes: 0

Views: 48

Answers (1)

Adiel
Adiel

Reputation: 3071

Actually, the datetime class has "properties", so you can get only the hours from all the data:

hours=[DV(:).Hour];

Now, you want only the dates that their "Hour" is 5:

result=DV(hours==5)

Upvotes: 2

Related Questions