Averaging the previous 5 values of every 30 values in a matrix
조회 수: 2 (최근 30일)
이전 댓글 표시
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
채택된 답변
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개)
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);
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!