Undefined function or variable

1 次查看(过去 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 个评论
economics student
economics student 2021-1-24
Undefined function or variable 'Date2Num'.
Error in VARToolbox_Primer (line 15)
datesnum = Date2Num(dates);
attached is the excel sheet. data come from sheet 1. As can be seen the dates are titled with t. But even when i try DateNumber = datenum(t) it doesnt work either.
dpb
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
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
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 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