필터 지우기
필터 지우기

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