Acquire annual data from table
Mostrar comentarios más antiguos
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 comentarios
dpb
el 16 de Dic. de 2021
Use a timetable instead and then retime with a custom function.
Florian van der Stap
el 16 de Dic. de 2021
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Data Preprocessing en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!