Averaging second data to minute data

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.

답변 (1개)

dpb
dpb 2018년 10월 10일

0 개 추천

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

Ayman Fathy
Ayman Fathy 2018년 10월 10일
It seems like I don't have the functions datatime, retime and array2timetable since I am using matlab 2012. Is there a way around it? Thanks
dpb
dpb 2018년 10월 10일
Upgrade? Much useful since then has been introduced.
Are your data sets complete; that is no missing observations?
Ayman Fathy
Ayman Fathy 2018년 10월 10일
I have 3 months of second data with some missing data in between so I believe I can't just take the average of every 60 rows. There has to be a method using the serial date numbers in the first column and use it to average the temperature data in the second column.
Ayman Fathy
Ayman Fathy 2018년 10월 10일
Please correct me if I am wrong. Thanks.
dpb
dpb 2018년 10월 10일
The missing values are a pain...that's why I suggested retime; it takes care of that for you.
Two basic choices, then.
  1. 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
  2. Find elements in each minute by binning with histc and averaging the elements of each bin.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Timetables에 대해 자세히 알아보기

질문:

2018년 10월 9일

댓글:

dpb
2018년 10월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by