Hi All!
I have a dataset (excel file attached - pcr.xlsx) of daily data values. The values are expressed as "Tonnes". I wanted to convert these to annual data from 1959 till date. My issue is that the daily data are irregular i.e. each year does not contain 365/366 values, so I am confused on how to directly get the answer (if each year had constant number of data points - 365, I think it would be easier).
I did try the "convert2annual" function but had no luck with it. I would appreciate some help in this regard. Thank you!

 採用された回答

Chunru
Chunru 2022 年 8 月 19 日
編集済み: Chunru 2022 年 8 月 19 日

0 投票

T = readtable("https://www.mathworks.com/matlabcentral/answers/uploaded_files/1101770/pcr.xlsx");
T(T.Tonnes == 0, :) =[]; % remove rows where Tonnes == 0
head(T)
ans = 8×2 table
Dates Tonnes ______________ ______ {'25-07-1959'} 319.76 {'25-07-1959'} 319.76 {'25-07-1959'} 4268.3 {'25-07-1959'} 2926.8 {'25-07-1959'} 3963.4 {'25-07-1959'} 1585.4 {'25-07-1959'} 975.7 {'25-07-1959'} 1524.4
T1 = timetable(datetime(T.Dates, "InputFormat", 'dd-MM-yyyy'), T.Tonnes);
T1.Properties.VariableNames = "Tonnes";
T2 = retime(T1, 'yearly', 'mean')
T2 = 61×1 timetable
Time Tonnes ___________ ______ 01-Jan-1959 1425.8 01-Jan-1960 2580.8 01-Jan-1961 1813.5 01-Jan-1962 2659.8 01-Jan-1963 1656.8 01-Jan-1964 1409.7 01-Jan-1965 1727.9 01-Jan-1966 1271.6 01-Jan-1967 1430.1 01-Jan-1968 1102.1 01-Jan-1969 1678.4 01-Jan-1970 1316.5 01-Jan-1971 1369.1 01-Jan-1972 1329.6 01-Jan-1973 1031.2 01-Jan-1974 1420.3

3 件のコメント

Keegan Carvalho
Keegan Carvalho 2022 年 8 月 19 日
編集済み: Keegan Carvalho 2022 年 8 月 19 日
Thanks @Chunru for your answer. However, there's a slight issue. I have re-attached the file here.
In the "Tonnes" column, there are zeros, so I wanted to take the annual mean by ignoring the zeros. I tried splitting the columns and used:
tonnes(tonnes==0) = []
But this eliminated the rows in the process. Could you please help me in calculating the annual means by ignoring the zeros in the "Tonnes" column?
Chunru
Chunru 2022 年 8 月 19 日
You can remove those rows in table before retime as updated above.
Keegan Carvalho
Keegan Carvalho 2022 年 8 月 19 日
Thanks you @Chunru I understood where I went wrong.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で MATLAB についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by