Converting string cell array to dates

조회 수: 3 (최근 30일)
Luc
Luc 2016년 11월 24일
댓글: dpb 2016년 11월 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
Luc
Luc 2016년 11월 30일
Great! It works now. Thanks everyone for your help!
dpb
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 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