Read timestamp from data file with mixed formats
이전 댓글 표시
I have a file with mixed date:
23.4 F15 2014-106T19:11:46
22.1 F16 2015-203T00:25:26
13.3 F100 2015-250T20:16:50
.
.
I know how to read the first two columns but I can't figure out how to scan the date and time from the third column. I tried:
formatSpec = '%f%s %{yyyy-DDDTHH:mm:ss}D';
delimiter = {'\t',' '};
dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter,...
'MultipleDelimsAsOne', true, 'ReturnOnError', false);
but I get the error 'Badly formed format string'
Does anyone know what format can be used for the third column? Thanks.
댓글 수: 3
per isakson
2015년 4월 20일
편집: per isakson
2015년 4월 20일
Your |formatSpec | looks okay to me. Which Matlab release do you use? R2014b needed.
Orion
2015년 4월 21일
dpb
2015년 4월 21일
The issue is as noted in the Answer previously posted that you didn't enclose the non-recognized ASCII character inside the date format string in single quotes to escape it from the rest of the format string.
채택된 답변
추가 답변 (1개)
Peter Perkins
2015년 4월 22일
0 개 추천
Hadi, in R2014b, you have the right format string for %D. But as Per points out, you need R2014b to use %D. In R2014a, you can read them as strings. But you have day-of-year in the strings, and the older datenum/datestr/datevec functions don't support that, so I think you're going to have to parse the separate pieces as numbers, and then put them together using datevec.
댓글 수: 1
dpb
2015년 4월 22일
Version issue aside, the doc gives an example using an embedded 'T' in the %D string and specifically notes it (the T or any other non-specific date character must be a single-quoted string???? (The point being the string as Hadi initially posted isn't formatted properly as I read the doc, anyway, or by the example)
카테고리
도움말 센터 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!