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

1 view (last 30 days)
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 Comment
dpb
dpb on 14 Nov 2021
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?

Sign in to comment.

Answers (0)

Categories

Find more on Dates and Time in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!