필터 지우기
필터 지우기

datetime to samplenumber slow

조회 수: 2 (최근 30일)
Lieke Numan
Lieke Numan 2019년 5월 23일
댓글: Lieke Numan 2019년 5월 23일
I have a very long vector with datetime and corresponding heart rate value. Now I want to calculate median value for every 5 minutes (my sample frequency is 4 seconds). However, sometimes some samples are missing. To be able to calculate the median value of HR every 5 minutes, I need to know which samples these are. I did it like this:
t1=time(1)
t2=time(end)
time5min=t1:minutes(5:t2)
for j=[time5min]
[~,ind1]=min(abs(datenum(time)-datenum(j-1)));
[~,ind2]=min(abs(datenum(time)-datenum(j)));
HR_med(ind2)=nanmedian(HR(ind1:ind2));
end
This is, as my vector is very large, very time consuming. Is there a faster way to do this?

답변 (1개)

Steven Lord
Steven Lord 2019년 5월 23일
Do you want to compute the median for overlapping / sliding windows of 5 minutes, or do you want to compute it for each non-overlapping 5 minute window of your time period?
If you want overlapping bins, use movmedian specifying your datetime array as the SamplePoints and the K or NB/NF inputs as a duration of minutes(5).
If you want non-overlapping bins, take a look at the groupsummary function.
  댓글 수: 1
Lieke Numan
Lieke Numan 2019년 5월 23일
It is okay to have one median value for each 5 minutes, so no sliding window.
I have another function for which I need to use these timestamps. I have number of steps for each sample, and I want to calculate the number of steps per 5 minutes. So i take the difference in "steps(X)-steps(X-5minutes)".

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

카테고리

Help CenterFile Exchange에서 Signal Generation and Preprocessing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by