how i average n values in array

if i have data a and i want to mean or average every 10 values as 1:10, 2:11, 3:12 and as so on for length of data ?

 采纳的回答

mean(reshape(YourData, 10, []))

8 个评论

But i need overlap between the values as 1:10 then from 2:11 and so on
arr=1:100;
for i=1:91
a=(arr(i:i+9));
mean(a)
end
please solve this error "Index exceeds matrix dimensions".
value of i should be 9 less than the last dimension of array (i.e.a in your case)
cs = cumsum(YourData);
moving_average = (cs(10:end) - cs(1:end-9))/10;
Hi Walter! Small correcting.
cs = cumsum(YourData(:));
moving_average = (cs(10:end) - [0;cs(1:end-10)])/10;

请先登录,再进行评论。

更多回答(2 个)

‘But i need overlap between the values as 1:10 then from 2:11 and so on’
Use a moving average filter:
Heart_pulse_avg = filter(ones(1,10), 10, Heart_pulse);
a - your vector;
out = movsum(a,[0 9],'Endpoints','discard')/10;

类别

帮助中心File Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by