Error using convert2quaterly: The value of 'TT1' is invalid.
6 views (last 30 days)
Show older comments
Leonardo Musati
on 17 Sep 2022
Commented: Leonardo Musati
on 17 Sep 2022
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 Comments
Accepted Answer
Star Strider
on 17 Sep 2022
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 Comments
More Answers (1)
Simon Chan
on 17 Sep 2022
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
See Also
Categories
Find more on Dates and Time in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!