フィルターのクリア

How to get textscan working with YY-MM-DD data?

1 回表示 (過去 30 日間)
Daniel Bridges
Daniel Bridges 2016 年 6 月 28 日
コメント済み: Stephen23 2019 年 11 月 19 日
I have a text file 'bankaccounttime.txt' with contents:
151215
151216
There is a blank line after the last entry, but the problem results even if I delete it. (Dates refer to 2015 December 15th, 2015 December 16th, but I intend to convert the entire column to serial date numbers via datenum and append the result to another time text file.)
Why does this command yield the following error? How do I fix it?
code:
bankaccounttime = textscan('data/bankaccounttime.txt','%{yMd}D')
error:
Error using textscan
Unable to read the DATETIME data with the format 'yMd'. If the data is
not a time, use %q to get string data.
  1 件のコメント
Daniel Bridges
Daniel Bridges 2016 年 6 月 28 日
編集済み: Daniel Bridges 2016 年 6 月 28 日
Following the textscan description more closely does not help:
banktimefileID = fopen('data/bankaccounttime.txt');
bankaccounttime = textscan(banktimefileID,'%{yMd}D')
fclose(banktimefileID);
Error using textscan
Unable to read the DATETIME data with the format 'yMd'. If the
data is not a time, use %q to get string data.
I have found an easier way to do what I want, although it does not answer the question:
booktimes = importdata('data/bankaccounttime.txt');
test1 = num2str(booktimes(1));
datenum(test1,'yymmdd')
ans =
736313.00

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

採用された回答

Stephen23
Stephen23 2016 年 6 月 28 日
編集済み: Stephen23 2016 年 6 月 28 日
According to the datetime properties linked to from the textscan docs, you should use this:
'%{yyMMdd}D'
  3 件のコメント
Justine Overacker
Justine Overacker 2019 年 11 月 18 日
編集済み: Justine Overacker 2019 年 11 月 18 日
I also have data in the yyMMdd format, but when I try to read it in using the '%{yyMMdd}D' identifier in textscan, I get the error message:
Error using textscan
Unable to read the DATETIME data with the format 'yyMMdd'. If the data is not a time, use %q to get string data.
I am using R2016a(9.0.0.341360). Help?
Stephen23
Stephen23 2019 年 11 月 19 日
@Justine Overacker: please upload a sample file by clicking the paperclip button.

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

その他の回答 (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