Converting string cell array to dates
3 次查看(过去 30 天)
显示 更早的评论
Hi,
I need to upload a large (100mb)comma separated .dat file in matlab 2008b. The first column of the file represents the date and time (yyyy-mm-dd HH:MM:SS.S). When I use the code below, the data upload fine and the first column comes out as "yyyy-mm-dd HH:MM:SS.S" in the cells. I am trying to convert this to serial dates using datenum? What I've tried so far resulted in this error message:
??? Error using ==> datenum at 174
DATENUM failed.
Error in ==> Load_and_graph_V5 at 6
Is the problem related to the " " at the begining and the end of the date?
datenum(T{1},formatIn)
fid = fopen('TOA5_TGA.RawData_47_2016_11_21_0000.dat', 'r');
T = textscan(fid, '%s%f%f%f%f%f%f%f%f%f%f%f%f%f', 'Delimiter',',','HeaderLines',4);
fclose(fid);
formatIn = 'yyyy-mm-dd HH:MM:SS.S';
datenum(T{1},formatIn)
Any help or suggestions would be appreciated!
Thanks
13 个评论
dpb
2016-11-30
I'll just note that perhaps could fix the problem in the place where the file was created initially to ensure consistent format.
I've bit^h^h^h complained to TMW previously over how fragile the time conversion format parsing is--it seems to me there should be no reason for it to fail there; the value is unambiguous. It'd be a reasonable enhancement request to suggest it not fail or, if that really is difficult owing to the way the C-based i/o formatting strings function, at least echo the line that caused the problem in the error.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Time Series Objects 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!