Averaging second data to minute data
Show older comments
Hello,
I have a file with 2 columns. First column is Date, second column is temperature. I would like to average the seconds data to minute data. Can someone please help? I would then like to convert the minute data to hourly data by taking into account only the 10 minutes interval of each hour. For example at 1pm, taking into account only the minute data from 12:55 to 1:05 Can someone please help?
I managed to read the csv file so now I have an array with 2 columns of date and second data. I would really appreciate it if someone helps.
Answers (1)
dpb
on 10 Oct 2018
Convert to timetable and use retime
tt_secs=array2timetable(data(:,2),'rowtimes',datetime(data(:,1))); % convert to timetable
tt_mins=retime(tt_secs,'minutely');
Going to hourly then shouldn't be too much of a stretch to guess! :)
You may have to provide the input format for the date data to datetime; you don't say how it's constructed.
5 Comments
Ayman Fathy
on 10 Oct 2018
dpb
on 10 Oct 2018
Upgrade? Much useful since then has been introduced.
Are your data sets complete; that is no missing observations?
Ayman Fathy
on 10 Oct 2018
Ayman Fathy
on 10 Oct 2018
dpb
on 10 Oct 2018
The missing values are a pain...that's why I suggested retime; it takes care of that for you.
Two basic choices, then.
- Interpolate and introduce NaN for missing seconds so can use the fixed number of seconds/minute to reshape() and average with nanmean to ignore the missing values, or
- Find elements in each minute by binning with histc and averaging the elements of each bin.
Categories
Find more on Timetables 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!