Error using convert2quaterly: The value of 'TT1' is invalid.
6 ビュー (過去 30 日間)
古いコメントを表示
Hi there,
I am trying to convert a weekly time series into a quaterly one.
This is the code I am using:
TT = readtable('data.xlsx');
TT1 = convert2quarterly(TT,'Aggregation',["lastvalue" "sum"]);
data.xlsx is an excel file with two columns, the first one has the time and the second one the values (attached).
While trying to do so I get the following error:
The value of 'TT1' is invalid. Expected TT1 to be one of these types:
timetable
Instead its type was table.
I have tried different options but I am really struggling to get the operation done.
I am super graterful for any possible hint/advice/code suggestions.
Thank you so much.
0 件のコメント
採用された回答
Star Strider
2022 年 9 月 17 日
The table argument has to be a timetable, so it must be converted after creating an appropriate datetime array for ‘date’.
T = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1127900/data.xlsx')
T.date = datetime(T.date);
TT = table2timetable(T);
TT1 = convert2quarterly(TT)
TT1 = convert2quarterly(TT,'Aggregation',["lastvalue" "sum"])
The 'Aggregation' does not work with ‘TT’. I have no experience with this function, so I have no idea what the problem may be.
.
2 件のコメント
その他の回答 (1 件)
Simon Chan
2022 年 9 月 17 日
Your data has only one column besides the date. So you can only state one method to your data.
The following shows an example when "sum" and "lastvalue" are selected as the Aggregation method.
opts = detectImportOptions('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1127900/data.xlsx');
opts = setvartype(opts,'date','datetime');
TT = readtimetable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1127900/data.xlsx',opts);
TT1 = convert2quarterly(TT,'Aggregation',"sum") % Use sum as the method
TT2 = convert2quarterly(TT,'Aggregation',"lastvalue") % Use lastvalue as the method
参考
カテゴリ
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!