Create time intervals of a time vector
조회 수: 30 (최근 30일)
이전 댓글 표시
Hi everyone!
I´m trying to create 15-minute intervals of a time vector. My original time vector is as follows:
09:00:16
09:00:17
09:00:18
09:00:25
...
09:15:16
09:15:17
..
09:30:16
09:30:17
..
up to the closing hour of the exchange
17:30:00
Is there anyway I could reduce this time vector to just something like :
09:00:00
09:15:00
09:30:00
09:45:00
10:00:00
up until the closing of the exchange
...
17:15:00
17:30:00
I would really appreciate any help, because I have been trying first to convert the time vector into numeric data and from that calculating the 15-minute intervals, but from there I don´t know how to bring it back to a time vector format. Especially because I am also computing 15-minute intervals of stock prices and I need to have it all together in a matrix of file together like this :
All=[Date Time Stock Price]
Once again thank you very much and have a very nice weekend :)
Lourdes
댓글 수: 0
채택된 답변
Oleg Komarov
2011년 5월 14일
Vector of 9:00 - 17:30 with 15 mins increments (24 hours a day, 96 quarters a day)
dv = 9/24:1/96:17/24+2/96;
Visualize result
datestr(dv)
ans =
9:00 AM
9:15 AM
...
5:30 PM
If you want to apply the solution to a range of days (eventually excluding saturdays and sundays):
1. Initial and final date
infi = {'15/01/2011'
'17/01/2011'};
days = infi(1):infi(2);
infi = datenum(infi,'dd/mm/yyyy');
2. Exclude sundays and saturdays (uncomment)
% days = days(~ismember(weekday(days),[1 7]));
3. Add dv
out = bsxfun(@plus, days, dv.');
4. Visualize result
datestr(out)
댓글 수: 4
Oleg Komarov
2011년 5월 14일
You can plot the series with the numeric dates and then use datetick to adapt to convert the labels to the desired date format (more feasible than scroolling down a cell array)
In general, to convert the numeric date to stringdate use datestr.
If you have troubles with textscan, open a new thread, post the first lines of your file, the code you're using (formatted), any error and the request for what you're trying to achieve.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Dates and Time에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!