datetime to samplenumber slow
1 回表示 (過去 30 日間)
古いコメントを表示
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?
0 件のコメント
回答 (1 件)
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.
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!