Averaging the previous 5 values of every 30 values in a matrix

3 ビュー (過去 30 日間)
Yoanna Ivanova
Yoanna Ivanova 2019 年 9 月 2 日
コメント済み: Yoanna Ivanova 2019 年 9 月 2 日
Hey guys,
I have this matrix that is 521x5 (in column 1 is subject number, in column 2 is experimental time, in column 3 is HR, etc..), I want to select one column from it (HR) and then select every 30th row and find the average of the previous 5 numbers in that column and insert them in a new matrix --- this is a bit confusing. Here is a bit of my code and I hope that makes it a bit more clear:
%read file
numData = xlsread (filename,'some phys parameters');
%experimental time is in column 2
experimentalTime = [30; 60; 90; 120; 150; 180; 210; 240; 270; 300; 330; 360; 390; 420; 450; 480; 510];
%HR is in column 3
HR = numData(31:30:end,3);
--> the code so far selects the HR at every 30 values starting at the 31st value and copies that into a new matrix but I need it to not select every 30th value but to take the average of the previous 5 rows in that column average that and then insert it into the new matrix. How can I do that? The 521 is experimental time in minutes, but I don't need all of that, I only need the experimental time at time points 30, 60, 90, etc and I wanted to average the HR at those time points by averaging the previous 5 entries , hope somehow this makes sense to you
  1 件のコメント
Andrei Bobrov
Andrei Bobrov 2019 年 9 月 2 日
Please attach your data here as mat - file.

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

採用された回答

darova
darova 2019 年 9 月 2 日
Use for loop
HR = numData(31:30:end,3);
meanHR = HR*0;
for i = 1:length(HR)
i1 = (-5:-1)+i*30; % (25:30) , (55:60) , (85:90)
meanHR(i) = mean( numData(i1,3) );
end
  1 件のコメント
Yoanna Ivanova
Yoanna Ivanova 2019 年 9 月 2 日
This is it. perfect. Thank you so much!!

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

その他の回答 (1 件)

Andrei Bobrov
Andrei Bobrov 2019 年 9 月 2 日
編集済み: Andrei Bobrov 2019 年 9 月 2 日
m = size(numData,1);
lo = mod((0:m-1)',30) + 1 >= 26;
ii = ceil((1:m)'/10);
HRmean5 = accumarray(ii(lo),numData(lo,3),[],@mean);

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by