# How to encompass a half-hour block of time?

1 visualizzazione (ultimi 30 giorni)
Cary il 21 Lug 2015
Modificato: Nitin Khola il 23 Lug 2015
The code below finds the index of every timestamp at 3:30.
timeStr=cellstr(datestr(time));
timeDbl=datevec(timeStr);
times=and(timeDbl(:,4)==14,timeDbl(:,5)==30);
priceIdx=find(times);
How can I encompass/index a half hour block of time? This is what I'm trying to do.
times=and(timeDbl(:,4)==14,timeDbl(:,5)==30:59);
Any suggestions?
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposta accettata

Nitin Khola il 23 Lug 2015
Modificato: Nitin Khola il 23 Lug 2015
As per my understanding, you wish to retrieve indices corresponding to values within a half hour interval, from a matrix which has date vectors as rows. This can be done using the "find" function, "&" logical operator, and the "and" function in a single command such as:
>> priceIdx=find(timeDbl(:,4)==9 & and(timeDbl(:,5)>30,timeDbl(:,5)<59 )) % interval of (9:30, 9:59)
I was able to retrieve row numbers containing values within the interval I specified. For example,
>> timeDbl =
2015 7 23 9 36 35
2015 7 23 9 28 39
2015 7 23 11 58 20
2015 7 23 9 56 20
>> priceIdx=find(timeDbl(:,4)==9 & and(timeDbl(:,5)>30,timeDbl(:,5)<59 )) % interval of (9:30, 9:59)
priceIdx =
1
4
##### 1 CommentoMostra -1 commenti meno recentiNascondi -1 commenti meno recenti
Cary il 23 Lug 2015
Thanks Nitin!

Accedi per commentare.

### Categorie

Scopri di più su Introduction to Installation and Licensing in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by