Acquire annual data from table
이전 댓글 표시
I am trying to calculate the annual cumulative freezing degree days from a dataset with air temperature observations. I came up with the below code, but the code 1) skips the final observation for each year and 2) the row index exceeds the table dimension. How can I better get the value for each year? And additionally is it also possible to get a value when the year is defined from july to june? I am using R2021b
T = readtable('RaaheNahkiainen.csv'); % skips the first row of data
T_f = -0.3; % freezing temperature
CFDD = zeros(T.Year(end) - T.Year(1) + 1,1); % annual cumulative freezing degree days to be filled
i = 2;
for j = 1:(T{end,1} - T{1,1} + 1)
while T{i,1} == T{i-1,1}
if T{i,6} < T_f
CFDD(j) = CFDD(j) + (T_f - T{i,6}) % add freezing degree days if temp is below freezing temperature
else
CFDD(j) = CFDD(j);
end
i = i + 1;
end
i = i + 1;
end
Thank you for your time!
댓글 수: 2
dpb
2021년 12월 16일
Use a timetable instead and then retime with a custom function.
Florian van der Stap
2021년 12월 16일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Data Preprocessing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!