# Determining the hourly time series from 5 minutes and 15 minutes time series data

29 views (last 30 days)
Answered: Lei Hou on 15 Feb 2022
I'm having a time series data of rainfall (5 minutes interval) and temperature (15 minutes interval) in .csv file. I need to determine the hourly rainfall (1hour interval) ie. adding the twelve 5 minutes data together and repeating it for entire time series and save it in another .csv file. Similarly for temperature data, I need to determine the hourly temperature (1hour interval) ie. averaging the four 15 minutes data together and repeating it for entire time series and save it in another .csv file. I'm attaching the time series data in .csv format.

David Hill on 3 Feb 2022
It you were not missing data it would be an easy reshape. I think you are going to need to do datenum ranges. Convert first column to datenum values, then run loop summing the entries every hour. You might need to fill in missing data in column 2 with zero. Might take awhile to compute.
t=zeros(size(c,1)-1,1);
for k=2:size(c,1)
t(k-1)=datenum(c{k,1});
end
ti=t(1);%start time
interVal=0.04167;
rain=cell2mat(c(2:end),2);
count=1;
for k=ti+interVal:interVal:t(end)
rainHourly(count)=sum(rain(t>=ti&t<k));
ti=k;
count=count+1;
end

Lei Hou on 15 Feb 2022
Hi Manikandan,
You can use timetable to store your data, and use retime to resample your data.
rainfall.DateTime = datetime(rainfall.DateTime,'InputFormat','dd-MM-uuuu HH:mm');
rainfallTT = table2timetable(rainfall);
rainfallHourly = retime(rainfallTT,'hourly','sum');
temperature.DateTime = datetime(temperature.DateTime,'InputFormat','dd-MM-uuuu HH:mm');
temperatureTT = table2timetable(temperature);
temperatureHourly = retime(temperatureTT,'hourly','mean');
writetimetable(rainfallHourly,'RainfallHourly.csv');
writetimetable(temperatureHourly,'TemperatureHourly.csv');
Thanks,
Lei
{"ft_lang_label":"__label__en","ft_lang_prob":0.7191675,"math_prob":0.8844088,"size":2244,"snap":"2023-14-2023-23","text_gpt3_token_len":588,"char_repetition_ratio":0.14419644,"word_repetition_ratio":0.104166664,"special_character_ratio":0.24108735,"punctuation_ratio":0.17084283,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9750491,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-03-23T11:32:33Z\",\"WARC-Record-ID\":\"<urn:uuid:b78213b5-1df7-4bca-9b41-d78c17d8daa1>\",\"Content-Length\":\"135942\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:7ea6f767-e922-478e-8fa9-c110ea24a637>\",\"WARC-Concurrent-To\":\"<urn:uuid:4e70970d-05ce-422d-a45c-b9b3cbd5e5fe>\",\"WARC-IP-Address\":\"104.86.80.92\",\"WARC-Target-URI\":\"https://ch.mathworks.com/matlabcentral/answers/1642605-determining-the-hourly-time-series-from-5-minutes-and-15-minutes-time-series-data\",\"WARC-Payload-Digest\":\"sha1:BCIGSFEY3MGPQZD2T4SIM23HWDCK4MYM\",\"WARC-Block-Digest\":\"sha1:SNTO3FE4EGIVKKF5LZVYUOTV6KBPPC5Y\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-14/CC-MAIN-2023-14_segments_1679296945144.17_warc_CC-MAIN-20230323100829-20230323130829-00736.warc.gz\"}"}