How to make datenum more efficient for large arrays?

3 次查看(过去 30 天)
I am using textscan() to create an matrix that is 3,081,680 rows long. The very first column, A{1}, is the timestamp column, and it's elements look like this:
"2011-01-23 18:38:30"
I have tried using datenum() to convert this, but it is either taking too long or not working at all (longer than ten minutes). Is there a way I can make this more efficient?
Thanks!

采纳的回答

Cedric
Cedric 2013-10-29
编辑:Cedric 2013-10-29
What is the purpose ultimately? Do you need an accurate time stamp which accounts for the date and time? If you were computing daily averages for 2011 only, for example, we could find a way to generate month/day IDs probably faster than DATENUM.
Otherwise, there are FEX contributions, e.g. this one by Jan Simon: http://www.mathworks.com/matlabcentral/fileexchange/28093-datestr2num
as well as a few relevant threads, among which: http://undocumentedmatlab.com/blog/datenum-performance/
  5 个评论
Marian
Marian 2013-10-30
Ah, datevec! I have been teaching myself MATLAB and did not know of this function, but I believe that I needed datevec to read arrays, as datenum or datestr2num would not work for type "cell". Thanks so much!
Cedric
Cedric 2013-10-30
You're welcome. Let me know if you go for an ACCUMARRAY approach for binning and need help with that.

请先登录,再进行评论。

更多回答(1 个)

Kelly Kearney
Kelly Kearney 2013-10-29
Are you specifying the date format? Particularly for large arrays,
datenum(A{1}, 'yyyy-mm-dd HH:MM:SS')
will be much faster than
datenum(A{1})
  3 个评论
Marian
Marian 2013-10-30
Error using datenum (line 179) DATENUM failed.
Error in onemin (line 9) time=datenum(A{1}, 'yyyy-mm-dd HH:MM:SS');
Caused by: Error using dtstr2dtnummx Failed on converting date string to date number.
This is the error I get using that, and I believe it is because of the double quotations around it.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Dates and Time 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by