Convert fdate1 class cell to fdate2 to class string to input into datenum; fdate2 still recognized as text by datenum

1 次查看(过去 30 天)
I've done this conversion many times from excel csv files through readtable.
Cannot figure out why datenum sees input fdate2, a string variable, as a text variable.
I've tried different formats, datevector... stumped
Thank you!
>> fdate1 = xusty(:,1);
% from readtable variable xusty= readtable('C:/Users/Owner/Documents/Research/Data/FRED/Treasuries/USTyields.csv');
fdate1(5:10,:)
ans =
6×1 cell array
{[01/05/1962]}
{[01/12/1962]}
{[01/19/1962]}
{[01/26/1962]}
{[02/02/1962]}
{[02/09/1962]}
>> class(fdate1)
ans =
'cell'
>> fdate2 = string(fdate1);
>> fdate2(5:10,:)
ans =
6×1 string array
"01/05/1962"
"01/12/1962"
"01/19/1962"
"01/26/1962"
"02/02/1962"
"02/09/1962"
>> class(fdate2)
ans =
'string'
>> fdate = datenum(fdate2,"mm/dd/yyyy");
Error using datenum (line 201)
DATENUM failed.
Caused by:
Error using dtstr2dtnummx
Failed to convert from text to date number.
>> fdate = datenum(fdate2,'mm/dd/yyyy');
Error using datenum (line 201)
DATENUM failed.
Caused by:
Error using dtstr2dtnummx
Failed to convert from text to date number.
>> fdate = datenum(fdate2,"MM/dd/yyyy");
Error using datenum (line 201)
DATENUM failed.
Caused by:
Error using dtstr2dtnummx
Failed to convert from text to date number.
  1 个评论
dpb
dpb 2021-11-14
Can't reproduce here w/ typing in values -- would have to have the input file and exact code to try to reproduce.
IME, the failure inside datenum internals has almost always occurred with an inconsistent input data set, but that doesn't seem the case here from what is shown, anyway.
One Q? would be why use the deprecated datenum over the newer and recommended datetime class?

请先登录,再进行评论。

回答(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