Undefined function or variable
조회 수: 6 (최근 30일)
이전 댓글 표시
Undefined function or variable 'Date2Num'. I am not sure whether this is due to a mix in coding from Python where Date2Num is used to convert date time objects to Matplotlib dates. What is the corresponding function in Matlab? Thanks in advance.
Error in VARToolbox_Primer (line 15)
datesnum = Date2Num(dates);
댓글 수: 7
dpb
2021년 1월 24일
Date2Num is not builtin MATLAB function so looks like you're missing an m-file that went with the code you do have or if it is an attempt to use a Python function I believe you have to import it somehow--I've never done that so don't know the specifics.
채택된 답변
dpb
2021년 1월 24일
편집: dpb
2021년 1월 24일
As noted above I don't know for certain whether the Date2Num is just a missing m-file or an attempt to use a Python function.
You don't need it though, and converting to use the new(ish) table object is probably worth the effort. It takes only a little bit of help for readtable and you have all the data in one table instead of text and numerics separate as with the deprecated xlsread route.
optMACRO=detectImportOptions('MACRO_US.xlsx','Sheet','Sheet1','NumHeaderLines',1);
tMACRO=readtable('MACRO_US.xlsx',optMACRO);
tMACRO.t=datetime(tMACRO.t,'InputFormat','yyyyQ','Format','yyyy''q''Q');
the result for the attached file is
>> head(tMACRO)
ans =
8×7 table
t cpi gdp unemp vix i1yr ebp
______ ______ _____ ______ _____ ____ _________
1989q1 51.333 52.3 5.2 17.82 9.29 0.4049
1989q2 52.162 52.7 5.2333 17.02 8.93 0.5758
1989q3 52.57 53.09 5.2333 18.08 8.1 0.7444
1989q4 53.105 53.19 5.3667 20.35 7.83 0.5925
1990q1 54.019 53.77 5.3 21.75 8.13 0.38887
1990q2 54.553 53.97 5.3333 18.68 8.27 0.14737
1990q3 55.495 54 5.7 25.08 7.83 -0.031533
1990q4 56.438 53.51 6.1333 25.99 7.3 0.2838
>>
댓글 수: 10
Walter Roberson
2021년 1월 27일
I recommend using pathtool as it gives a nice visual interface.
With pathtool items that are higher up in the list have priority over items lower down in the list.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Dates and Time에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!