Average of every nth value in a vector

6 ビュー (過去 30 日間)
Bethany Skinner
Bethany Skinner 2019 年 12 月 4 日
コメント済み: Andrei Bobrov 2019 年 12 月 4 日
I'm working on a project that will be measuring heart rate over long periods of time (8+ hours), and the data will be sampled every 0.1s. This will give me far more data than I would like/need! I'm looking to average the data to give me HR every 1 minute. The example data set that I'm working with at the moment is a vector of 137255x1 and I want to be able to average every 600 values. Is it possible to do this?
Thank you in advance!

回答 (2 件)

Matt J
Matt J 2019 年 12 月 4 日
tmp=conv(yourvector, ones(600,1)/600,'valid');
result=tmp(1:600:end)

Andrei Bobrov
Andrei Bobrov 2019 年 12 月 4 日
編集済み: Andrei Bobrov 2019 年 12 月 4 日
Let A - your array 137255 x 1
n = numel(A);
TT = timetable(A,'RowTimes',(0:n-1)'*saconds(.1));
out = retime(TT,'minutely','mean');
or
i = ceil((1:numel(A))'/600);
out = accumarray(i,A,[],@mean);
  2 件のコメント
Bethany Skinner
Bethany Skinner 2019 年 12 月 4 日
Thanks for your answer - I've tried the first option and it returns the following error when running the final line:
"Error using timetable/retime. All variables in inpur timetables must be numeric, datetime, or duration when synchronizing using 'mean'."
Would you know how to fix this?
Andrei Bobrov
Andrei Bobrov 2019 年 12 月 4 日
Please attach small interval of your "The example data..." as mat-file.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeWorkspace Variables and MAT-Files についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by