retrieve data containing date and time from text file

5 ビュー (過去 30 日間)
bayern science
bayern science 2018 年 9 月 29 日
編集済み: dpb 2018 年 10 月 4 日
Hi all,
I encountered the following strange problem when trying to retrieve date and time and other data from a text string.
The following runs OK.
>>tmp = '460018898104779 6d0502fb0be52d 2018-09-27 23:59:48';
>>test2 = textscan(tmp, '%f%14c%{yyyy-MM-dd HH:mm:ss}D', 'Delimiter',{'\n'});
But when I append two more doubles to the text string and run
>>tmp = '460018898104779 6d0502fb0be52d 2018-09-27 23:59:48 113.944081 22.504949';
>>test2 = textscan(tmp, '%f%14c%{yyyy-MM-dd HH:mm:ss}D%f%f', 'Delimiter',{'\n'});
It gives the following error message:
>>Error using textscan
>>Unable to read the DATETIME data with the format 'yyyy-MM-dd HH:mm:ss'. If the data is not a time, use %q to get text data.
Could somebody help to clarify what has gone wrong? Thank you very much!
Bayern

採用された回答

Walter Roberson
Walter Roberson 2018 年 9 月 29 日
You should use Delimiter '\t' rather than \n
  8 件のコメント
bayern science
bayern science 2018 年 10 月 4 日
Many thanks for digging deep into the format dpb! You have made the thread more helpful!
dpb
dpb 2018 年 10 月 4 日
NB: I corrected original mistake of 'whitespace' for 'delimiter' in first paragraph regarding textscan propensity to add the blank even if not user-provided.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by