hi,
i have a .txt file containing dates in such a format : Sat Oct 01 20:00:00 BST 2011, where BST stands for British Summer Time. I want to read the file and transform to datenums based on the format: 01-Oct-2011 20:00:00 is there any quick way (in terms of processing as some files contain more than 10000 dates) to do this? Thanks in advance, ~Conrad

 채택된 답변

Daniel Shub
Daniel Shub 2011년 10월 25일

1 개 추천

Assuming that all the dates are in BST and that you are not trying to adjust for different time zones ...
x = 'Sat Oct 01 20:00:00 BST 2011';
datestr(datenum(x([1:20,25:28]), 'ddd mmm dd HH:MM:SS yyyy'), 'dd-mmm-yyyy HH:MM:SS')

댓글 수: 4

Daniel Shub
Daniel Shub 2011년 10월 25일
I am sure Jan is going to chime in with a date solution that is 100x faster. It will probably be similar to something in this blog: http://undocumentedmatlab.com/blog/datenum-performance/
Jan
Jan 2011년 12월 12일
@Daniel: I'm so sorry, I've been on holidays in October. What about this:
x = 'Sat Oct 01 20:00:00 BST 2011';
y = x([9:11, 5:8, 25:28, 11:19])
y([3, 7]) = '-';
1000 conversions need 0.03 seconds (Matlab 2009a/64), while the DATENUM-methods needs 1.01 seconds. This is a speedup of only 30 - sorry.
Daniel Shub
Daniel Shub 2011년 12월 12일
I think that is probably the fastest way. I didn't realized that all that was needed was a reorganization of the array.
Jan
Jan 2011년 12월 12일
@Daniel: A lot of performance and confusion problems can be solved by the KISS rule: Keep it simple stupid.
I've learned programming on a ZX81 with 1kB RAM. Neither DATENUM, nor DATESTR, nor the underlying C-mex functions would match in this microscopic box anymore, but the barely dull indexing trick would.
Even an Arduiono feels like a mainframe computer, if you are old enough...

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Time Series Objects에 대해 자세히 알아보기

제품

태그

Community Treasure Hunt

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

Start Hunting!

Translated by