Help Optimize slow Datestr() function performance
3 次查看(过去 30 天)
显示 更早的评论
I have imported a large text file with textual dates in the format m/d/yyyy. The end result that I need is a numeric date (for export to another system) in the format yyyymmdd. Since my text file is rather large (850,000 rows) my current method for conversion is really slow. It's taking about 50 seconds for the single line of code to run and is about 75% of my code's total run time. Since I have to run this code iteratively at times I'm interested in any suggestions to optimize how I'm using datestr, or an alternative.
Here's my code
tic
MyDates = str2num(datestr(MyData{1,2},'yyyymmdd'));
toc
yields - Elapsed time is 49.348078 seconds.
2 个评论
采纳的回答
Walter Roberson
2014-1-17
t = datevec(MyData{1,2});
MyDates = t(:,1) * 10000 + t(:,2) * 100 + t(:,3);
3 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!