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!