Error using convert2quaterly: The value of 'TT1' is invalid.
조회 수: 1 (최근 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에서 Tables에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!